Saturday, 14 September 2024

Practical - 62 - Write a program in python that takes two numbers from the user and check whether 1st number is divisible by 2nd number or not. print “Divisible” if number is divisible otherwise print “Not Divisible”

Practical - 62 - Write a program in python that takes two numbers from the user and check whether 1st number is divisible by 2nd number or not. print “Divisible” if number is divisible otherwise print “Not Divisible”


Ans:

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

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

if a%b==0:

    print("Divisible")

else:

    print("Not Divisible")

 

Output:

Enter first number: 15

Enter second number: 3

Divisible

OR

Enter first number: 15

Enter second number: 4

Not Divisible


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