Python Assignment Answers
Python Assignment Answers
1RN19CS067
ANS:
n1 = int(input())
n2 = int(input())
else:
ANS:
n1 = int(input())
n2 = int(input())
n3 = int(input())
else:
ANS:
num = int(input())
if(num>=1):
elif(num<=-1):
else:
print(num," is zero....")
ANS:
num = int(input())
else:
ANS:
num = int(input())
if(num % 2 == 0):
else:
ANS:
year = int(input())
else:
ANS:
print("Enter a character")
ch = input()
if(((ch >= 'A') and (ch <= 'Z')) or ((ch >='a') and (ch <='z'))):
print(ch," is an alphabet")
else:
ANS:
#8) program to input any alphabet and check whether it is vowel or consonant.
ch = input()
print(ch," is a vowel")
else:
print(ch," is a consonent")
9) Program to input any character and check whether it is alphabet, digit or special
character.
ANS:
#9) program to input any character and check whether it is alphabet, digit or special character.
ch = input()
if(((ch >= 'A') and (ch <= 'Z')) or ((ch >='a') and (ch <='z'))):
print(ch," is an alphabet")
print(ch," is a number")
else:
ANS:
ANS:
weekno = int(input())
if(weekno == 1):
print("Sunday")
if(weekno == 2):
print("Monday")
if(weekno == 3):
print("Tuesday")
if(weekno == 4):
print("Wednesday")
if(weekno == 5):
print("Thursday")
if(weekno == 6):
print("Friday")
if(weekno == 7):
print("Saturday")
12) Program to input month number and print number of days in that month.
ANS:
#12) program to input month number and print number of days in that month.
month_no = int(input())
if((month_no==1)or(month_no==3)or(month_no==5)or(month_no==7)or(month_no==8)or(month_no=
=10)or(month_no==12)):
print("31 days")
if((month_no==2)or(month_no==4)or(month_no==6)or(month_no==9)or(month_no==11)):
print("30 days")
14) Program to input angles of a triangle and check whether triangle is valid or not.
ANS:
#14) program to input angles of a triangle and check whether triangle is valid or not.
a1 = int(input())
a2 = int(input())
a3 = int(input())
sumOfAngles = a1 + a2 + a3
if(sumOfAngles == 180):
print("Valid Triangle...")
else:
print("Invalid Triangle...")
15) Program to input all sides of a triangle and check whether triangle is valid or not.
ANS:
#15) program to input all sides of a triangle and check whether triangle is valid or not.
side2 = int(input())
side3 = int(input())
print("Valid Triangle...")
else:
print("Invalid Triangle...")
16) Program to check whether the triangle is equilateral, isosceles or scalene triangle.
ANS:
#16) program to check whether the triangle is equilateral, isosceles or scalene triangle.
a1 = int(input())
a2 = int(input())
a3 = int(input())
if(a1 == a2 == a3):
print("Equilateral Triangle")
print("Isosceles Triangle")
else:
print("Scalene Triangle")
ANS:
sprice = int(input())
cprice = int(input())
print("Profit: ",sprice-cprice)
else:
print("Loss: ",cprice-sprice)
19)
Program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and
Computer. Calculate percentage and grade according to following:
Percentage >= 90%: Grade A
Percentage >= 80%: Grade B
Percentage >= 70%: Grade C
Percentage >= 60%: Grade D
Percentage >= 40%: Grade E
Percentage < 40%: Grade F
ANS:
#19) program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and
Phy = float(input())
Chem = float(input())
biology = float(input())
math = float(input())
cs = float(input())
average = total / 5
20) Program to input basic salary of an employee and calculate its Gross salary
According to following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary > 20000: HRA = 30%, DA = 95%
ANS:
#20) 20. program to input basic salary of an employee and calculate its Gross salary according to
following:
Basic_Salary = float(input())
if(Basic_Salary <=10000):
HRA=(Basic_Salary*20)/100
DA = (Basic_Salary*80)/100
HRA = (Basic_Salary*25)/100
DA = (Basic_Salary*90)/100
else:
HRA = (Basic_Salary*30)/100
DA = (Basic_Salary*95)/100
21) Program to input electricity unit charges and calculate total electricity bill according to the
Given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
ANS:
#21) program to input electricity unit charges and calculate total electricity bill according to the given
condition:
print("Enter the number of units")
units=int(input())
bill_amt=0.0
if(units<=50):
bill_amt=units*0.50
bill_amt=((units-50)*0.75)+(50*0.50)
bill_amt=((units-150)*1.20)+(100*0.75)+(50*0.50)
else:
bill_amt=((units-250)*1.5)+(150*1.20)+(100*0.75)+(50*0.50)
total_amt=float(bill_amt)+(0.20*float(bill_amt))
THANK YOU