Branching
Branching
1. Write a Python program that takes a number from the user and see if it is divisible by: [The
codes for each of the subproblems will be different]
a. Both 5 and 7
b. 5 or 7
c. 5 and not 7
d. Either 5 or 7 but not both
If yes, the print “Yes”, otherwise, print “No”. The first one is done for you.
c d
2. Take a number from the user and print whether it is “Odd” or “Even”, and whether it is
“Positive”, “Negative” or “Zero”.
Sample Input #1 #Your code here
14
Output:
Even
Positive
Sample Input #2
-1
Output:
Odd
Negative
Sample Input #3
0
Output:
Even
Zero
Worksheet 2: Branching | CSE110 |
3. Take the quiz, mid and final marks of a student, calculate the total marks and print the total marks
and grade based on the following table.
Total >= 90 A
80 <= Total <= 89 B
70 <= Total <= 79 C
50 <= Total <= 69 D
Total < 50 F
Sample Input #1: #Your code here
Quiz: 20
Mid: 25
Final: 45
Output:
Total Marks: 90
Grade: A
Sample Input #2:
Quiz: 18
Mid: 20
Final: 36
Output:
Total Marks: 74
Grade: C
4. Imagine you want to buy a car. So, you went to a car shop. Depending on the brand, wheel
position and horse-power you have to pay some extra tax. Here are the rules:
• If the car is Ferrari, you have to pay 30% extra tax, If the car is Ford, you have to pay
25% extra tax
• If the car is left-wheeled, you have to pay 10% extra tax
• If the car uses above 2000 horse-power, you have to pay 10% extra tax.
Now from user, take input the brand of the car (“Ford”/ “Ferrari”), whether it is right or left
wheeled (“Right”/ “Left”), and how much horse-power it uses (int). Now calculate the total
extra percentage (%) of tax the user has to pay. [Hint: you have to declare a variable and set its
value to zero and then keep on adding all the taxes with that variable.]
Sample Input #1: #Your code here
Brand: Ford
Wheel: Left
Horse-Power: 2500
Output:
Extra Tax: 45%