Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views13 pages

Program List 2

The document contains a list of programming exercises written by Aishwarya Thakur, focusing on basic programming concepts such as conditionals, loops, and user input in Python. Each exercise includes a problem statement, input requirements, and expected output. The exercises cover various topics including eligibility checks, mathematical calculations, and simple data validation.

Uploaded by

aishwaryath903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

Program List 2

The document contains a list of programming exercises written by Aishwarya Thakur, focusing on basic programming concepts such as conditionals, loops, and user input in Python. Each exercise includes a problem statement, input requirements, and expected output. The exercises cover various topics including eligibility checks, mathematical calculations, and simple data validation.

Uploaded by

aishwaryath903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Computer Science File

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:

Q2) Write a program to check whether a person is a senior citizen or not.

Input:
a=int(input("Enter age of person "))
if(a>=60):
print("senior citizen")
else:
print("not a senior citizen")

Output:

Q3) Write a program to check whether a number is divisible by both 2 and 3.

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:

Q4) Write a program to test the divisibility of a number with another


number.

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:

Q5) Write a program to accept the temperature in degrees Celsius of water


and check whether it is boiling or not.

Input:
t=int(input("Enter temperature of water in celsius: "))
if(t>=100):
print("Water is boiling")
else:
print("Water is not boiling.")

Output:

Q5) Write a program to check whether a number is divisible by 7 or not.


Input:
n=int(input("Enter Number: "))
if(n%7==0):
print("Divisible by 7")
else:
print("Not Divisible by 7")

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:

Q8) Write a program to display “Hello” if a number entered is a multiple of


5, otherwise print “Bye”.

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:

Q11) Write a program to find whether a number is positive, negative or zero.

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:

Q12) Write a program to check whether a triangle is valid or not based on


angles.
Input:
a1=int(input("Enter angle 1: "))
a2=int(input("Enter angle 2: "))
a3=int(input("Enter angle 3: "))
if(a1+a2+a3==180):
print("Triangle is valid")
else:
print("Invalid Triangle")

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:

Q21) Write a program to check whether a character is a vowel or not.

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:

Q23) Write a program to calculate and print the root of a quadratic


equation:ax2+bx+c=0.
Input:
a=int(input("Enter coefficient of x^2:"))
b=int(input("Enter coefficient of x:"))
c=int(input("Enter the constant:"))
d=(b*b)-(4*a*c)
if(d>0):
p=(-b+(d**(1/2)))/(2*a)
q=(-b-(d**(1/2)))/(2*a)
print("two distinct real zeroes are:",p,q)
elif(d==0):
p=(-b)/(2*a)
print("two identical zeroes are",p,p)
else:
print("No real zeroes")

Output:

Q24) Write a program to check whether the last digit of a number


(entered by user) is divisible by 3 or not.
Input:
n=int(input("Enter number:"))
a=n
d=n%10
if(d%3==0):
print("Last digit of",a,"is divisible by 3")
else:
print("Last digit of",a,"is not divisible by 3")
Output:

Q25) Write a program to accept the length and breadth of a rectangle


from the user and check whether or not it is a square.
Input:
l=int(input("Enter length of rectangle:"))
b=int(input("Enter the breadth of rectangle:"))
if(l==b):
print("Given rectangle is a square.")
else:
print("Given rectangle is not a square.")

Output:

Q26) A company decided to give a bonus of 5% to employees if their years


of service are more than 5 years. Ask users for their salary and years
of service and print the net bonus amount.
Input:
sal=int(input("Enter your salary:"))
yos=int(input("Enter years of service:"))
if(yos>5):
total=((5/100)*sal)+(sal)
print("net bonus amount is:", total)
else:
total=sal
print("net bonus amount is:", total)

Output:

Q27) Write a program to compute a gross salary. Taking names of the


employees and the basic salary as input.
Input:
emp_n=str(input("Enter name of employee:"))
basic=int(input("Enter basic salary:"))
if(basic>=45000):
da=(40/100)*basic
hra=(30/100)*basic
gross=basic+da+hra
print("Gross salary of ",emp_n, "is ",gross)
elif(basic<45000 and basic>=3000):
da=(40/100)*basic
hra=(25/100)*basic
gross=basic+da+hra
print("Gross salary of ",emp_n, "is ",gross)
elif(basic<3000 and basic>15000):
da=(30/100)*basic
hra=(20/100)*basic
gross=basic+da+hra
print("Gross salary of ",emp_n, "is ",gross)
elif(basic<=15000):
da=(30/100)*basic
hra=(15/100)*basic
gross=basic+da+hra
print("Gross salary of ",emp_n, "is ",gross)

Output:

Q28) Write a program to calculate simple interest using formula


SI=P*R*T/100. Rate will be 5% if the principal amount is less than 25000
otherwise rate will be 8%.
Input:
P=int(input("Enter principal amount:"))
T=int(input("Enter time:"))
if(P>25000):
R=5
else:
R=8
SI=(P*R*T)/100
print("simple interest is ", SI)
Output:

Q29) Write a program to calculate BMI of a person after inputting its


weight in kgs and height in meters and then print their nutritional
status:
Input:
w=float(input("Enter Weight in kilogrammes:"))
h=float(input("Enter Height in meters:"))
bmi=w/(h**2)
if(bmi<18.5):
print("Underweight")
elif(bmi>=18.5 and bmi<=24.9):
print("Normal")
elif(bmi>=25 and bmi<=29.9):
print("Overweight")
elif(bmi>30):
print("Obese")

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:

Q31) Write a program to accept three sides from a triangle and


check whether it is an equilateral, isosceles or scalene triangle.
Input:
s1=float(input("Enter first side:"))
s2=float(input("Enter second side:"))
s3=float(input("Enter third side:"))
if(s1==s2 and s2==s3):
print("Given triangle is an Equilateral Triangle")
elif((s1==s2 and s1!=s3) or (s1==s3 and s1!=s2) or (s2==s3 and s2!=s1)):
print("Given triangle is an Isosceles Triangle")
elif(s1!=s2 and s1!=s3):
print("Given triangle is an Scalene Triangle")

Output:

You might also like