0% found this document useful (0 votes)
9 views

Conditional Statement

The document contains 10 Python programming problems related to conditional statements and solutions to each problem. For each problem, the code prints the name and student ID, takes input, applies conditions to the input, and prints the output.

Uploaded by

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

Conditional Statement

The document contains 10 Python programming problems related to conditional statements and solutions to each problem. For each problem, the code prints the name and student ID, takes input, applies conditions to the input, and prints the output.

Uploaded by

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

Python Practice Problems: Conditional Statements

1. Given two integer numbers return their sum. If the sum is greater than 100, then
return their product.

Program print('Shreyas soni\n0827CS191224')


a=int(input("Enter 1st no,:"))
b=int(input("Enter 2nd no.:"))
def function(a,b):
if(a+b>100):
return a*b
else:
return a+b
print(function(a,b))

Output Shreyas soni


0827CS191224
Enter 1st no,:200
Enter 2nd no.:2
400

2. Write a Python program to calculate the sum of three given numbers, if the values
are not - equal then return four times of their sum

Program print('Shreyas soni\n0827CS191224')


def sum(x,y,z):
if(x==y==z):
return x+y+z
else:
return (x+y+z)*4
a=int(input("Enter 1st no,:"))
b=int(input("Enter 2nd no.:"))
c=int(input("Enter 3rd no.:"))
print(sum(a,b,c))

Output Shreyas soni


0827CS191224
Enter 1st no,:1
Enter 2nd no.:2
Enter 3rd no.:3
24

3. A shop will give discount of 50% if the cost of purchased quantity is more than
10000. Ask user for quantity suppose, one unit will cost 100. Judge and print total
cost for user.

Program print('Shreyas soni\n0827CS191224')


quantity = int(input("Enter quantity"))
if quantity*100 > 10000:
print ("Cost is",((quantity*100)-(.5*quantity*100)))
else:
print ("Cost is",quantity*100)
Output Shreyas soni
0827CS191224
Enter quantity500
Cost is 25000.0

4. To check whether a number is divisible by 8 and 12 or not.

Program print('Shreyas soni\n0827CS191224')


n=int(input("Enter no."))
if (n%8==0 and n%12==0):
print ("No. is divisible by 8 and 12")
else:
print ("No. is not divisible by 8 and 12")

Output Shreyas soni


0827CS191224
Enter no.24
No. is divisible by 8 and 12

5. To check whether a given number is even or odd.

Program print('Shreyas soni\n0827CS191224')


num = int(input("Enter a number: "))
if (num % 2) == 0:
print("No. is Even".format(num))
else:
print("No. is Odd".format(num))

Output Shreyas soni


0827CS191224
Enter a number: 8
No. is Even

6. Write a 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

Program print('Shreyas soni\n0827CS191224')


english = float(input(" Please enter English Marks: "))
math = float(input(" Please enter Math score: "))
computers = float(input(" Please enter Computer Marks: "))
physics = float(input(" Please enter Physics Marks: "))
chemistry = float(input(" Please enter Chemistry Marks: "))
t=english+math+computers+physics+chemistry
p=(t/500)*100
if(p>=90):
print("Grade A")
elif(p>=80 and p<90):
print("Grade B")
elif(p>=70 and p<80):
print("Grade C")
elif(p>=60 and p<70):
print("Grade D")
elif(p>=40 and p<60):
print("Grade E")
else:
print("Grade F")

Output Shreyas soni


0827CS191224
Please enter English Marks: 90
Please enter Math score: 80
Please enter Computer Marks: 60
Please enter Physics Marks: 70
Please enter Chemistry Marks: 65
Grade C

7. Take input of age of 3 people by user and determine oldest and youngest among
them.

Program print('Shreyas soni\n0827CS191224')


person1 = eval(input("Enter age of person 1 : "))
person2 = eval(input("Enter age of person 2 : "))
person3 = eval(input("Enter age of person 3 : "))
if person1 > person2 and person1 > person3:
print("Person 1 is oldest")
elif person2 > person1 and person2 > person3:
print("Person 2 is oldest")
elif person3 > person1 and person3 > person2:
print("Person 3 is oldest")
if person1 < person2 and person1 < person3:
print("Person 1 is youngest")
elif person2 < person1 and person2 < person3:
print("Person 2 is youngest")
elif person3 < person1 and person3 < person2:
print("Person 3 is youngest")

Output Shreyas soni


0827CS191224
Enter age of person 1 : 23
Enter age of person 2 : 18
Enter age of person 3 : 45
Person 3 is oldest
Person 2 is youngest

8. Write a 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

Program print('Shreyas soni\n0827CS191224')


e=int(input("enter electricity unit:"))
if e<=50:
amt=e*0.50
elif e<=150:
amt=50*0.50+(e-50)*0.75
elif e<=250:
amt=50*0.50+(e-50)*0.75+(e-150)*1.20
else:
amt=220+(e-250)*1.50
charge=amt*0.20
total=amt+charge
print("Total Bill is: ",total)

Output Shreyas soni


0827CS191224
enter electricity unit:70
Total Bill is: 48.0

9. A student will not be allowed to sit in exam if his/her attendence is less than 80%.
Take following input from user
Total Number of classes held
Total Number of classes attended. And print percentage of class attended. Is
student is allowed to sit in exam or not.

Program print('Shreyas soni\n0827CS191224')


a=int(input("Number of classes held:"))
b=int(input("Number of classes attended:"))
percentage=b/a*100
print("percentage of class attended: ",percentage)
if percentage>=80:
print("The student is allowed to sit in the exam hall")
else:
print("The student is not allowed to sit in the exam
hall")

Output Shreyas soni


0827CS191224
Number of classes held:100
Number of classes attended:85
percentage of class attended: 85.0
The student is allowed to sit in the exam hall

10. Calculate income tax for the given income by adhering to the below rules
Taxable Income Rate (in %)
First Rs.10,0000 0
Next Rs. 10,0000 10
The remaining 20

Program print('Shreyas soni\n0827CS191224')


income=int(input("Enter your income:"))
if(income<=100000):
print("No Income Tax")
elif(income<=200000):
inc=100000+(income-100000)*0.10
print("taxable income is:",inc)
else:
inc = 200000+(income-200000)*0.20
print("taxable income is:", inc)

Output Shreyas soni


0827CS191224
Enter your income:100000
No Income Tax

You might also like