Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background Programs are more interesting when they involve the user - supplying values to use in calculations, asking for names, and so on. We

Background Programs are more interesting when they involve the user - supplying values to use in calculations, asking for names, and so on. We can get a string from the user via the input() function, and then convert to other types as needed via other built-in functions of Python, such as int(), float(), and bool() Variables give us the chance to store values for later, recallable by name. We can even repeatedly update the value associated with that name, as a replacement: forgetting the old value forever, remembering the new value until further notice. As procedural programs are very much a sequence of executed instructions, the exact order of when we store (or replace) a value for a variable, and when we look up and use the current value, is an important part of understanding how we solve a programming task Functions help us write reusable pieces of code that can receive multiple different arguments, saving us from writing the input) interaction code with the user (its also much harder to test/award credit otherwise!). We will be writing different function definitions like in lab, to show our understanding of Python concepts This project will get us using variables while calculating different things. Wel1l explore control structures next, so be sure to master these more basic tasks now The current project has two tasks: calculate the total of an order of hotdogs and corn, and convert duration in seconds to a more human-friendly time report in the form of (days, hours, minutes, seconds). Theres also some extra credit calculating the classic two-cyclist problem! ®

Background Programs are more interesting when they involve the user - supplying values to use in calculations, asking for names, and so on. We can get a string from the user via the input() function, and then convert to other types as needed via other built-in functions of Python, such as int(), float(), and bool(). Variables give us the chance to store values for later, recallable by name. We can even repeatedly update the value associated with that name, as a replacement: forgetting the old value forever, remembering the new value until further notice. As procedural programs are very much a sequence of executed instructions, the exact order of when we store (or replace) a value for a variable, and when we look up and use the current value, is an important part of understanding how we solve a programming task. Functions help us write reusable pieces of code that can receive multiple different arguments, saving us from writing the input() interaction code with the user (it's also much harder to test/award credit otherwise!). We will be writing different function definitions like in lab, to show our understanding of Python concepts. This project will get us using variables while calculating different things. We'll explore control structures next, so be sure to master these more basic tasks now. The current project has two tasks: calculate the total of an order of hotdogs and corn, and convert duration in seconds to a more human-friendly time report in the form of (days, hours, minutes, seconds). There's also some extra credit calculating the classic two-cyclist problem! Tasks There are two required tasks, and one extra credit (worth 5%). Read the descriptions here, and fill out the template provided. 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) total (2, 0) total (0, 4) total(10, 5) 0 2.5 2.0 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) report_time (79) report_time(43500) report_time (93603) (0,0,0,7) (0,0,1,19) (0,12,5,0) (1,2,0,3) Extra Credit! distances_to_meet (speed1_fps, speed2_fps, track_length_feet): This function solves the classic math problem: assume two people are cycling around a track; they start at the same time but ride at different speeds. We need to calculate the distance they each travel before they meet again on the track. Notes: o Assume both speed are positive integers given as feet per second; o The track length is given as an integer number of feet; o You should return two integers as the number of feet in a tuple; you need to use int() to convert your final answers to ints; o We do not know which cyclist travels faster; o Here are some sample calls and their expected answers. distances_to_meet (10, 20, 100) distances_to_meet (10,5,40) distances_to_meet (12,5, 200) (100, 200) (80,40) (342, 142)

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

Python version 36 Python program to create and test functions total reporttime and distancestomeet def totalnumhotdog numcorn Function that takes as i... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cost management a strategic approach

Authors: Edward J. Blocher, David E. Stout, Gary Cokins

5th edition

73526940, 978-0073526942

More Books

Students also viewed these Programming questions

Question

b. What is the persons job title?

Answered: 1 week ago

Question

x-y=2 y=(1)/(2)x Enter the correct answers in the boxes

Answered: 1 week ago