0% found this document useful (0 votes)
21 views2 pages

Branching

The document contains 4 programming problems involving conditional logic: 1) Write a program to check if a number is divisible by 5 and/or 7. 2) Write a program to determine if a number is even/odd and positive/negative/zero. 3) Write a program to calculate student grades based on total marks and assign a letter grade. 4) Write a program to calculate total extra tax percentage based on car brand, wheel position, and horsepower.

Uploaded by

Kazi Tasmia
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)
21 views2 pages

Branching

The document contains 4 programming problems involving conditional logic: 1) Write a program to check if a number is divisible by 5 and/or 7. 2) Write a program to determine if a number is even/odd and positive/negative/zero. 3) Write a program to calculate student grades based on total marks and assign a letter grade. 4) Write a program to calculate total extra tax percentage based on car brand, wheel position, and horsepower.

Uploaded by

Kazi Tasmia
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/ 2

Worksheet 2: Branching | CSE110 |

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.

a num= int (input( )) b


if num%5 == 0 and num%7 == 0:
print(“Yes”)
else:
print(“No”)

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%

Sample Input #2:


Brand: Ferrari
Wheel: Right
Horse-Power: 2000
Output:
Extra Tax: 30%

You might also like