I need help with raptor program Trying to Get Some Exercise You have decided tha
ID: 3797112 • Letter: I
Question
I need help with raptor program
Trying to Get Some Exercise
You have decided that you need to start eating better and getting some exercise. Since you like ridingyour bike when the weather is nice and you have access to stationary bike when the weather is not good,you decide to start cycling every day. Also you want to keep better track of the calories you haveconsumed throughout the day. At the end of the week you want to know the following:
What is the total calories consumed and burned for each day? Assume that for every minute you
are cycling you burn 10 calories.What is the deficit or difference between the number of calories you consume and burn?What is the average calories that you burn and consume?What day did you consume the highest amount of calories? What day did you burn the highestcalories?What day did you consume the least amount of calories? What day did you burn the least calories?
Every day you plan on logging in a notebook the total number of calories you consume(approximately) and how many minutes you spend on either or both bikes. At the end of the week youplan on loading all of these numbers into a program so that you can analyze the data.
Program Requirements
Your program will need to do the following:
Feature a menu so that all you need to do is enter a letter and the program will perform thenecessary task. Use the following letters to correspond to what the program needs to do:
Menu Option Operation
T Get Total Calories Consumed and Burned. This will also print out calories consumed and burned per day
D Get the deficit or difference between the calories consumed and burned for each day
A Get the averages
H Get the highest calories consumed and burned and the corresponding days in which this happened
L Get the lowest calories consumed and burned and the corresponding days in which this happened
E Exit or exits the program
Make sure that whatever choice you make from the menu that it is validated and will not cause theprogram to stop prematurelyAllow you to pick numerous tasks before you are done with the program. HINT: you will need aloop here.Load both Cycling and Eating amounts when the program loads. In other words, you will not getprompted to load these values separately. Instead you will initialize your arrays with thesenumbers at the beginning of the program.Nice clean output.Utilization of modular programming. At the minimum you should have 5 modules.
Some Help with the Logic
This program will need to use numerous modules. After you code each module, run it to test it anddebug it, if necessary. Do not move on to your next module until you have successfully tested the moduleyou are currently working on
It is all in the Planning
Open up Notepad++ and start to figure out what this program needs to do, the inputs, the outputs,the variables, the 30,000 foot view and your pseudocode.
Time to Test the Logic
Now that you have planned out your attack, test your logic using Raptor. Use the following test datato test your program.
Cycling Eating
15 2,600
10 2,400
20 3,500
18 3,200
25 2,700
10 3,300
5 3,000
Explanation / Answer
def print_menu():
print('T - Get Total Calories Consumed and Burned.')
print('D - Get the deficit or difference between the calories consumed and burned for each day.')
print('H - Get the highest calories consumed and burned and the corresponding days in which this happened.')
print('L - Get the lowest calories consumed and burned and the corresponding days in which this happened.')
print('E - Exit')
def get_user_choice():
print_menu()
while True:
choice = raw_input('Enter your choice:')
choice = choice.upper()
if choice in ['T', 'D', 'H', 'L', 'E']:
return choice
else:
print('Invalid choice. Try again!!')
def load_data():
file_name = raw_input('Enter file name: ')
with open(file_name) as f:
lines = f.readlines()
lines = [filter(lambda data: data != '', line.strip().split('-')) for line in lines] # remove '-' characters
day_data = [[int(data[0]), int(data[1].replace(',', ''))] for data in
lines[1:]] # convert string data into integer data
return day_data
def total_calories(data):
total_consumed = 0
total_burnt = 0
for i, day in enumerate(data):
total_consumed += day[1]
total_burnt += day[0] * 10
print('Calories consumed on day' + str(i + 1) + ' is ' + str(day[1]))
print('Calories burnt on day' + str(i + 1) + ' is ' + str(day[0] * 10))
print('Total calories consumed: ' + str(total_consumed))
print('Total calories burnt: ' + str(total_burnt))
def deficit(data):
for i, day in enumerate(data):
print('Calories deficit on day' + str(i) + ' is ' + str(day[1] - (day[0] * 10)))
def highest(data):
highest_burnt_index = 0
highest_consumed_index = 0
for i, day in enumerate(data):
if day[0] > data[highest_burnt_index][0]:
highest_burnt_index = i
if day[1] > data[highest_consumed_index][1]:
highest_consumed_index = i
print('Highest calories consumed is ' + str(data[highest_consumed_index][1]) + ' and is on day ' + str(highest_consumed_index + 1))
print('Highest calories burnt is ' + str(data[highest_burnt_index][0] * 10) + ' and is on day ' + str(highest_burnt_index + 1))
def lowest(data):
lowest_burnt_index = 0
lowest_consumed_index = 0
for i, day in enumerate(data):
if day[0] < data[lowest_burnt_index][0]:
lowest_burnt_index = i
if day[1] < data[lowest_consumed_index][1]:
lowest_consumed_index = i
print('Lowest calories consumed is ' + str(data[lowest_consumed_index][1]) + ' and is on day ' + str(lowest_consumed_index + 1))
print('Lowest calories burnt is ' + str(data[lowest_burnt_index][0] * 10) + ' and is on day ' + str(lowest_burnt_index + 1))
def process_command(data, choice):
if choice == 'T':
total_calories(data)
elif choice == 'D':
deficit(data)
elif choice == 'H':
highest(data)
elif choice == 'L':
lowest(data)
def main():
data = load_data()
print(data)
while True:
choice = get_user_choice()
if choice == 'E':
break
else:
process_command(data, choice)
main()
OutPut:
Enter file name: data.txt
[[15, 2600], [10, 2400], [20, 3500], [18, 3200], [25, 2700], [10, 3300], [5, 3000]]
T - Get Total Calories Consumed and Burned.
D - Get the deficit or difference between the calories consumed and burned for each day.
H - Get the highest calories consumed and burned and the corresponding days in which this happened.
L - Get the lowest calories consumed and burned and the corresponding days in which this happened.
E - Exit
Enter your choice:T
Calories consumed on day1 is 2600
Calories burnt on day1 is 150
Calories consumed on day2 is 2400
Calories burnt on day2 is 100
Calories consumed on day3 is 3500
Calories burnt on day3 is 200
Calories consumed on day4 is 3200
Calories burnt on day4 is 180
Calories consumed on day5 is 2700
Calories burnt on day5 is 250
Calories consumed on day6 is 3300
Calories burnt on day6 is 100
Calories consumed on day7 is 3000
Calories burnt on day7 is 50
Total calories consumed: 20700
Total calories burnt: 1030
T - Get Total Calories Consumed and Burned.
D - Get the deficit or difference between the calories consumed and burned for each day.
H - Get the highest calories consumed and burned and the corresponding days in which this happened.
L - Get the lowest calories consumed and burned and the corresponding days in which this happened.
E - Exit
Enter your choice:D
Calories deficit on day0 is 2450
Calories deficit on day1 is 2300
Calories deficit on day2 is 3300
Calories deficit on day3 is 3020
Calories deficit on day4 is 2450
Calories deficit on day5 is 3200
Calories deficit on day6 is 2950
T - Get Total Calories Consumed and Burned.
D - Get the deficit or difference between the calories consumed and burned for each day.
H - Get the highest calories consumed and burned and the corresponding days in which this happened.
L - Get the lowest calories consumed and burned and the corresponding days in which this happened.
E - Exit
Enter your choice:H
Highest calories consumed is 3500 and is on day 3
Highest calories burnt is 250 and is on day 5
T - Get Total Calories Consumed and Burned.
D - Get the deficit or difference between the calories consumed and burned for each day.
H - Get the highest calories consumed and burned and the corresponding days in which this happened.
L - Get the lowest calories consumed and burned and the corresponding days in which this happened.
E - Exit
Enter your choice:L
Lowest calories consumed is 2400 and is on day 2
Lowest calories burnt is 50 and is on day 7
T - Get Total Calories Consumed and Burned.
D - Get the deficit or difference between the calories consumed and burned for each day.
H - Get the highest calories consumed and burned and the corresponding days in which this happened.
L - Get the lowest calories consumed and burned and the corresponding days in which this happened.
E - Exit
Enter your choice:E
Process finished with exit code 0