Total (num_hotdog, num_corn): This function starts off knowing how many hotdogs
ID: 3873604 • Letter: T
Question
Total (num_hotdog, num_corn): This function starts off knowing how many hotdogs and how many corns are included in an order, you can just use those two parameters to calculate. (Assume they're non-negative numbers). Given the price is $1.25 for one hotdog and $0.50 for one corn, your job is to calculate and return how many dollars to pay for that order. Here are some sample calls and their expected answers. total(0, 0) rightarrow 0 total (2, 0) rightarrow 2.5 total(0, 4) rightarrow 2.0 total(10, 5) rightarrow 15.0 report_time(duration): This function knows how many seconds there are for a given duration (assume this is a non-negative integer). Your job is to report the time as a total of days, hours, minutes, and seconds. Since we need to give back four pieces of information, we return a tuple of them, in order of days, hours, minutes, and seconds: if I wanted to return one day, two hours, zero minutes, and three seconds, I'd end my call with return(1,2,0,3). Of course, your code needs to use variables so that it works for whatever inputs there are! Here are some sample calls and their expected answers. report_time (7) rightarrow (0, 0, 0, 7) report_time (79) rightarrow (0, 0, 1, 19) report_time (43500) rightarrow (0, 12, 5, 0) report_time (93603) rightarrow (1, 2, 0, 3)Explanation / Answer
#!usr/bin/python
def total(num_hotdog, num_corn):
return (num_hotdog*1.25 + num_corn * 0.5)
def report_time(duration):
d = int(duration/86400)
rem = duration % 86400
h = int(rem/3600)
rem = rem % 3600
m = int(rem/60)
s = rem % 60
return d,h,m,s
print(total(0,0))
print(total(2,0))
print(total(0,4))
print(total(10,5))
d,h,m,s = report_time(7)
print(d,h,m,s)
d,h,m,s = report_time(79)
print(d,h,m,s)
d,h,m,s = report_time(43500)
print(d,h,m,s)
d,h,m,s = report_time(93603)
print(d,h,m,s)