Program List 2
Program List 2
Program List 1
Aishwarya Thakur
Q1) Write a program to check whether a person is eligible for voting or
not.
Input:
a=int(input("Enter age of person "))
if(a>=18):
print("Eligible for voting")
else:
print("Not Eligible for voting")
Output:
Input:
a=int(input("Enter age of person "))
if(a>=60):
print("senior citizen")
else:
print("not a senior citizen")
Output:
Input:
n=int(input("Enter number:"))
if n%2==0:
if n%3==0:
print(n, "is divisible by both 2 and 3")
else:
print(n, "is not divisible by both 2 and 3")
if n%3==0 and n%2!=0:
print(n, "is only divisible by 3")
else:
print(n, "is only divisible by 2")
Output:
Input:
n1=int(input("Enter First Number a: "))
n2=int(input("Enter Second Number b: "))
if (n1%n2==0 or n2%n1==0):
print("The numbers are divisible.")
Output:
Input:
t=int(input("Enter temperature of water in celsius: "))
if(t>=100):
print("Water is boiling")
else:
print("Water is not boiling.")
Output:
Output:
Q7) Write a program to find out whether a given number is odd or even.
Input:
a=int(input("Enter Number: "))
if(a%2==0):
print(a, "is even")
else:
print(a, "is odd")
Output:
Input:
a=int(input("Enter number: "))
if(a%5==0):
print("Hello")
else:
print("Bye")
Output:
Q9) Write a program that asks the user to enter a length in centimeters and
convert it to inches but show that entry is invalid if value is negative.
Input:
cm=float(input("Enter value in centimeters: "))
if(cm<0):
print("Entry is invalid")
else:
print(cm/2.54, "inches")
Output:
Q10) If the ages of Ram, Shyam and Ajay are given, write a program to
determine the youngest of the three.
Input:
ram=int(input("Enter age of Ram:"))
shyam=int(input("Enter age of Shyam:"))
ajay=int(input("Enter age of Ajay:"))
if(ram<shyam and ram<ajay):
print("Ram is the youngest")
elif(shyam<ram and shyam<ajay):
print("Shyam is the youngest")
else:
print("Ajay is the youngest")
Output:
Input:
n=int(input("Enter number: "))
if(n==0):
print|("Number is zero.")
elif(n<0):
print("Number is negative.")
else:
print("Number is positive")
Output:
Output:
Q13) Find the absolute value of a number entered through the keyboard.
Input:
n=int(input("Enter number- "))
if(n>0):
print(n)
elif(n<0):
print(-1*n)
else:
print()
Output:
Q14) Given the length and breadth of a rectangle, find whether the area of
the rectangle is greater than its perimeter.
Input:
l=intinput("Enter the length"))
b=int(input("Enter the breadth"))
a=l*b
p=2*(l+b)
if(a>p):
print("area is greater than perimeter")
else:
print("area is not greater than perimeter")
Output:
Q15) If the cost price and selling price of an item is entered, find out if
the seller incurred profit or loss and print it.
Input:
sp=int(input("Enter selling price: "))
cp=int(input("Enter cost price: "))
if(cp>sp):
print("Loss of", (cp-sp), "hasccured.")
elif(cp<sp):
print("Profit of", (sp-cp), "has occured.")
else:
print("No profit or loss has occured")
Output:
Q16) Write a program to input two numbers and an operator and perform the
operation.
Input:
a=float(input("Number 1 "))
b=float(input("Number 2 "))
c=str(input("Operator"))
if(c=='+'):
print(a+b)
elif(c=='-'):
print(a-b)
elif(c=='*'):
print(a*b)
elif(c=='/'):
print(a*b)
elif(c=='//'):
print(a//b)
elif(c=='%'):
print(a%b)
elif(c=='**'):
print(a**b)
else:
print("Invalid Input(s)")
Output:
Q17) Write a program to accept percentages from the user and display the
grade according to the following criteria.
Input:
p=float(input("Enter Percentage "))
if(p>90):
print("Grade is A")
elif(p>80 and p<=90):
print("Grade is B")
elif(p>=60 and p<=80):
print("Grade is C")
else:
print("Grade is D")
Output:
Q18) Write a program to accept a number from 1 to 7 and display the name of
the day like 1 for Sunday etc.
Input;
n=int(input("Enter Number 1 TO 7 "))
if(n==1):
print("Sunday")
elif(n==2):
print("Monday")
elif(n==3):
print("Tuesday")
elif(n==4):
print("Wednesday")
elif(n==5):
print("Thursday")
elif(n==6):
print("Friday")
elif(n==7):
print("Saturday")
else:
print("Invalid Input")
Output:
Q19) Accept any city from the user and display monuments of the city.\
Input:
city=str(input("Enter City Name "))
if(city=="Delhi" or city=="delhi"):
print("Red Fort")
elif(city=="Agra" or city=="agra"):
print("Taj Mahal")
elif(city=="Jaipur" or city=="jaipur"):
print("Jal Mahal")
else:
print("City does not Exist")
Output:
Input:
al=(input("Enter Alphabet "))
if(al=='a' or al=='e' or al=='i' or al=='o' or al=='u'):
print("Given Alphabet is a Vowel")
else:
print("Given Alphabet is not a Vowel.")
Output:
Q22) Write a program to accept total number of working days and total number
of absent days and verify whether
Input:
w=int(input("Enter Total Number of Working Days"))
a=int(input("Enter Total Number of Days Absent"))
at=(w-a)/w*100
if(at>=75):
print("Attendance is Adequate")
else:
print("Attendance is Inadequate")
Output:
Output:
Output:
Output:
Output:
Output:
Q30) Write a program to calculate the bonus for employees, based on the
following conditions: if the employee is male, the bonus will be 10% of
the salary where the salary is less than 50,000; otherwise, the bonus
will be 15%. If the employee is female, the bonus will be 20% of the
salary where the salary is less than 50,000; otherwise, the bonus will
be 25%.
Input:
gender=input("Enter gender(male/female): ")
salary=int(input("Enter salary:"))
if(gender=='male'):
if(salary<50000):
bonus=(10/100)*salary
print("total salary is", bonus+salary)
else:
bonus=(15/100)*salary
print("total salary is", bonus+salary)
elif(gender=='female'):
if(salary<50000):
bonus=(20/100)*salary
print("total salary is", bonus+salary)
else:
bonus=(25/100)*salary
print("total salary is", bonus+salary)
Output:
Output: