Saturday, 14 September 2024

Practical - 61 - Write a program in python that takes age as input from the user and if age is greater than or equal 18 then print “YOU CAN VOTE” otherwise print “YOU CAN NOT VOTE”.

Practical - 61 - Write a program in python that takes age as input from the user and if age is greater than or equal 18 then print “YOU CAN VOTE” otherwise print “YOU CAN NOT VOTE”.


Ans:

age=int(input("Enter your age: "))

if age>=18:

    print("YOU CAN VOTE")

else:

    print("YOU CAN NOT VOTE")

 

Output:

Enter your age: 21

YOU CAN VOTE

OR

Enter your age: 17

YOU CAN NOT VOTE

Practical - 60 - Write a program in python to input two numbers and prints “SAME” if both the numbers are either even or both are odd otherwise prints “NOT SAME”.

Practical - 60 - Write a program in python to input two numbers and prints “SAME” if both the numbers are either even or both are odd otherwise prints “NOT SAME”.


Ans:

a=int(input("Enter first number: "))

b=int(input("Enter first number: "))

if(a%2==0 and b%2==0) or (a%2==1 and b%2==1):

    print("SAME")

else:

    print("NOT SAME")

 

Output:

Enter first number: 7

Enter first number: 8

NOT SAME

OR

Enter first number: 6

Enter first number: 8

SAME

OR

Enter first number: 5

Enter first number: 7

SAME

Practical - 59 - Write a program in Python to input a number and check whether it is even or odd.

Practical - 59 - Write a program in Python to input a number and check whether it is even or odd.


Ans:

n=int(input("Enter a number: "))

if n%2==0:

    print(n,"is an even number")

else:

    print(n,"is an odd number")

 

Output:

Enter a number: 5

5 is an odd number

OR

Enter a number: 6

6 is an even number

Practical - 58 - Write a Python program to take temperature in Celsius as input and convert it to Fahrenheit.

Practical - 58 - Write a Python program to take temperature in Celsius as input and convert it to Fahrenheit.


Ans:

C=float(input("Enter the temperature in Celsius: "))

F=1.8*C+32

print("Temperature in Fahrenheit=", F)

 

Output:

Enter the temperature in Celsius: 37

Temperature in Fahrenheit= 98.6


Practical - 57 - Write a Python program to take temperature in Fahrenheit as input and convert it to Celsius.

Practical - 57 - Write a Python program to take temperature in Fahrenheit as input and convert it to Celsius.


Ans:

F=float(input("Enter the temperature in Fahrenheit: "))

C=5*(F-32)/9

print("Temperature in Celsius=", C)

 

Output:

Enter the temperature in Fahrenheit: 98.6

Temperature in Celsius= 37.0


Practical - 56 - Write a Python Program which accepts three numbers from user and displays their sum and average.

Practical - 56 - Write a Python Program which accepts three numbers from user and displays their sum and average.


Ans:

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

c=int(input("Enter third number: "))

sum=a+b+c

avg=sum/3

print("Sum=",sum)

print("Average=",avg)

 

Output:

Enter first number: 8

Enter second number: 5

Enter third number: 11

Sum= 24

Average= 8.0


Practical - 55 - Write a program in Python which accepts two numbers and calculate their sum, difference, multiplication and division.

Practical - 55 - Write a program in Python which accepts two numbers and calculate their sum, difference, multiplication and division.


Ans:

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

print("Sum=",a+b)

print("Difference=",a-b)

print("Multiplication=",a*b)

print("Division=",a/b)

 

Output:

Enter first  number: 8

Enter second number: 5

Sum= 13

Difference= 3

Multiplication= 40

Division= 1.6


Practical - 54 - Write a program in Python that accepts side of a square and find the area of the square.

Practical - 54 - Write a program in Python that accepts side of a square and find the area of the square.


Ans:

side=float(input("Enter the side of square: "))

area=side*side

print("Area=",area)

 

Output:

Enter the side of square: 8

Area= 64.0


Practical - 53 - Write a program in Python that accepts radius of a circle and prints its area.

 Practical - 53 - Write a program in Python that accepts radius of a circle and prints its area.


Ans:

radius=float(input("Enter the radius of a circle: "))

pi=3.14

area=pi*radius**2

print("Area=",area)

 

Output:

Enter the radius of a circle: 10

Area= 314.0

Tuesday, 10 September 2024

Operator precedence and associativity Practice questions in python

 What will be the output of following statement?

1.     22 % 3

2.     47%6

3.     -47%6

4.     47%-6

5.     -47%6

6.     2+3-1*2*3*2

7.     3*1**3

8.     2+9*((3*12)-8)/10

9.     4//2*3+5/2+1

10.  43.55+2/2

11.  4.00/(2.0+2.0)

12.  (2-6+3**2*3)+7

13.  24//6%3

14.  24//4//2

15.  x>>2=2

16.  x<<2

17.  4^12

18.  not(3>4)

19.  not(1&1)

20.  13.25+4/2

21.  3+3.00

22.  3**3.0

23.  343%15

24.  14 + 14%15//4

25.  5*10+11/2

26.  8*2+4**2//5-3

27.  1+(2-3)*4**5//6

28.  5%3+4**2

29.  6+5/4**2//5+8

30.  16*5/4*2/5-8

31.  6/3 + 4**3//8-4

32.  4+3*5/3-5%2

33.  5+3**2/2

34.  3-2**2**3+99/11

35.  15.0/4+(8+3.0)

36.  10 * (3 + 5) // 2

37.  8 / 2 + 2 * 3

38.  5 + 2 * 3 ** 2

39.  8 % 3 + 2 ** 2 * (2 + 2)

40.  (3 + 2) * 4 / 2 ** 2

41.  7<4 or 6>3 and not 10 ==10 or 17>4

42.  5<10 and 12>7 or not 7>4

43.  not(True) and False

44.  True or False

45.  not(False and True)

46.  True and not(False)

47.  4 < 5 and 5 < 6

48.  3 != 3 or 5 > 4

49.  10 == 10 and 5 > 6

50.  (5 != 5) or (6 >= 6)

51.  (6 > 5) or (7 <= 7)

52.  10 > 5 < 2

53.  3 * "Hello"