Question : 19
Write a python script to take input for a number check and print whether the number is even, odd or zero?
Sol:( Method:1)
a=int(input("Enter any no "))
if(a==0):
print("Number is zero")
else:
if(a%2==0):
print("Number is even")
else:
print("Number is odd")
Sol: (Method:2)
a=int(input("Enter any no "))
if(a==0):
print("Number is zero")
elif(a%2==0):
print("Number is even")
else:
print("Number is odd")
Output:
Enter any no 25
Number is odd
>>>
Enter any no 0
Number is zero
>>>
Enter any no 12
Number is even
>>>
Question: 20
Write a python script to take input for three number check and print the largest number? (Method:1)
Sol:
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
print("max no = ",a)
else:
if(b>c):
print("max no = ",b)
else:
print("max no = ",c)
using elif
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
print("max no = ",a)
elif(b>c):
print("max no = ",b)
else:
print("max no = ",c)
Output:
Enter 1st no 25
Enter 2nd no 63
Enter 3rd no 98
max no = 98
>>>
Enter 1st no 85
Enter 2nd no 25
Enter 3rd no 45
max no = 85
>>>
Question: 21
Write a python script to take input for three number check and print the largest number? (Method:2)
Sol:
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
m=a
else:
if(b>c):
m=b
else:
m=c
print("max no = ",m)
Using elif
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
m=a
elif(b>c):
m=b
else:
m=c
print("max no = ",m)
Output:
Enter 1st no 25
Enter 2nd no 63
Enter 3rd no 68
max no = 68
>>>




