Python Assignment –5
Write a program to accept a month number and display month name. e.g. if entered number is 1 the display January, if 2 then display February
and so on. In case any other number is entered then display Invalid Month Number.
Code:
A=int(input("Enter number in month="))
if A==1:
print("The month is January")
elif A==2:
print("The month is February")
elif A==3:
print("The month is March")
elif A==4:
print("The month is April")
elif A==5:
print("The month is May")
elif A==6:
print("The month is June")
elif A==7:
print("The month is July")
elif A==8:
print("The month is August")
elif A==9:
print("The month is September")
elif A==10:
print("The month is October")
elif A==11:
print("The month is November")
elif A==12:
print("The month is December")
else:
print("There is no month for",A)
2. Write a program to accept week day number and display week day name. e.g. if entered
number is 1 the display Monday, if 2 then display Tuesday and so on. In case any other number
is entered then display Invalid Week Day Number.
Code:
A=int(input("Enter number in days="))
if A==1:
print("The day is Sunday")
elif A==2:
print("The day is Monday")
elif A==3:
print("The day is Tuesday")
elif A==4:
print("The day is Wednesday")
elif A==5:
print("The day is Thursday")
else:
print("The day is invalid")
3. Write a program to accept 1 number between 11 and 20 and display it in words.
Code:
A=int(input("Enter a number between 11 and 20="))
if A==11:
print("The number is 11")
elif A==12:
print("The number is 12")
elif A==13:
print("The number is 13")
elif A==14:
print("The number is 14")
elif A==15:
print("The number is 15")
elif A==16:
print("The number is 16")
elif A==17:
print("The number is 17")
elif A==18:
print("The number is 18")
elif A==19:
print("The number is 19")
elif A==20:
print("The number is 20")
else:
print("This number is invalid")
4. Write a program to accept three numbers and display largest of entered three numbers.
Code:
A=int(input("Enter the first number"))
B=int(input("Enter the second number"))
C=int(input("Enter the third number"))
if A>B>C:
print(A,"is grater than ",B,"is greater than ",C)
elif A>C>B:
print(A,"is grater than ",C,"is greater than ",B)
elif B>C>A:
print(B,"is grater than ",C,"is greater than ",A)
elif B>A>C:
print(B,"is grater than ",A,"is greater than ",C)
elif C>B>A:
print(C,"is grater than ",B,"is greater than ",A)
elif C>A>B:
print(C,"is grater than ",A,"is greater than ",B)
5. Write a program to accept three numbers and display smallest of entered three numbers
Code:
A=int(input("Enter the first number"))
B=int(input("Enter the second number"))
C=int(input("Enter the third number"))
if A<B<C:
print(A,"is lesser than ",B,"is lesser than ",C)
elif A<C<B:
print(A,"is lesser than ",C,"is lesser than ",B)
elif B<C<A:
print(B,"is lesser than ",C,"is lesser than ",A)
elif B<A<C:
print(B,"is lesser than ",A,"is lesser than ",C)
elif C<B<A:
print(C,"is lesser than ",B,"is lesser than ",A)
elif C<A<B:
print(C,"is lesser than ",A,"is lesser than ",B)
6. Write a program to accept three numbers and display middle number (neither large nor small).
Code:
A=int(input("Enter the first number"))
B=int(input("Enter the second number"))
C=int(input("Enter the third number"))
if A<B<C:
print(B,"is the middle number")
elif A<C<B:
print(C,"is the middle number")
elif B<C<A:
print(C,"is the middle number")
elif B<A<C:
print(A,"is the middle number")
elif C<B<A:
print(B,"is the middle number")
elif C<A<B:
print(A,"is the middle number")