Computer Science Practice Assignement
Computer Science Practice Assignement
Computer Science Practice Assignement
16 17 12 -> 50
12 13 14 -> 30
6 4 4 -> 10
Exercise 3-4
To be discussed in Tutorial
Your task is to implement an algorithm that can calculate your maximum heart rate and your optimal
training pulse for fat-burning, endurance increase or cardiovascular system improvement. The Formula
for calculating the maximum heart rate (Pulse) depends on the age and the gender:
• Health zone: This amounts to 50-60% of the maximum heart rate. Within this pulse range
particularly the cardiovascular system will be invigorated. This range is particularly suitable for
beginners.
1
• Fat burning zone: This amounts to 60-70% of the maximum heart rate. Within this pulse range,
most calories from fat are burned. Furthermore the cardiovascular system will be trained.
• Aerobic zone: This amounts to 70-80% of the maximum heart rate. Within this pulse range,
carbohydrates and fats are burned for power production in the muscle cells. This range requires
the cardiovascular system as well as the lung and the metabolism.
• Anaerobic zone: This amounts to 80-90% of the maximum heart rate. Within this pulse range,
the body cannot cover the oxygen demand any longer. This range is for the development of power
and muscle mass.
• Red zone: This amounts to 90-100% of the maximum heart rate. This pulse range should be
handled with caution. It is dangerous for beginners and can be harmful for the heart.
a) Write an algorithmthat given the age and the gender should display the different zones. For example,
your algorithm should display the following for a 45 years old man:
b) Write an algorithm that given the age, the gender and the heart rate will display the corresponding
zone. For example, the algorithm should display for a 45 years old man and heart rate of 190, the
following message
Red Zone
Your algorithm should consist of only if then statements, i.e. you are not allowed to use any else
statements.
Given the cost of the purchase, write an algorithm to calculate and print the money paid taking into
consideration the 10% sales taxes. The taxes are calculated on the amount after the discount.
• Input a dog’s age in human years: 2 The dog’s age in dog years is 21
• Input a dog’s age in human years: 15 The dog’s age in dog years is 73
• Input a dog’s age in human years: -5 Age must be positive number.
2
• The capacity of the gas tank, in Gallons.
• The indication of the gas gauge in percent (full=100, three quarters=75 and so on).
• The miles per gallon of the car.
Tank Capacity: 12
Gas Gauge Reading in percent: 50
Miles per Gallon: 30
Get Gas!
The algorithm should print out Get gas or Safe to proceed depending on if the car can cross the 200
miles with the gas remaining in the tank.
• A: 85-100
• B: 74-85
• C: 60-74
• D: 50-60
• F: <50
Keeping in mind that a student cannot score more than 105 marks, nor less than 0 marks.
Write an algorithm that reads each student’s marks, print either a grade or an error message.
3
Exercise 3-11 Student School
To be solved in Tutorial
The following algorithm prints out whether a current student is in elementary (1st - 5th), middle (6th -
8th), or high school (9th - 12th).
grade = eval(input())
if(grade <= 5):
print("this student is in elementary school")
elif(grade <= 8):
print("this student is in middle school")
elif(grade <= 12):
print("this student is in high school")
a) Write an equivalent algorithm that will print the same messages as the algorithm above without
using any nested if-statements.
b) Discuss the drawback of your algorithm? Hint: Compare the efficiency of both algorithms.