Background Programs are more interesting when they involve the user - supplying values to use in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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) 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)
Expert Answer:
Answer rating: 100% (QA)
Python version 36 Python program to create and test functions total reporttime and distancestomeet def totalnumhotdog numcorn Function that takes as i... View the full answer
Related Book For
Cost management a strategic approach
ISBN: 978-0073526942
5th edition
Authors: Edward J. Blocher, David E. Stout, Gary Cokins
Posted Date:
Students also viewed these programming questions
-
The norm of a linear transformation TA: Rn Rn can be defined by where the maximum is taken over all nonzero x in Rn. (The subscript indicates that the norm of the linear transformation on the left is...
-
Suppose that f: Rn R and g: Rn Rn are differentiable on Rn and that there exist r > 0 and a Rn such that Dg(x) is the identity matrix, I, for all x Br(a). Prove that there is a function h: Br(a) {a}...
-
Let 5: Rn Rn and T: Rn Rn be linear transformations with matrices A and B respectively. [Theorem 3.] (a) Show that B2 = B if and only if T2 = 7 (where T2 means T o T). (b) Show that B2 = 1 if and...
-
The position of a particle moving along 12t2 2t, where r is in meters and t is in an r-axis is given by x = seconds. i Determine the acceleration of the particle at t = 3.0 s. ii What are the...
-
If the index of refraction of the cladding material in Example 8-5 is increased to 1.50, what would be the new maximum usable data rate?
-
A construction worker accidentally drops a hammer from a height of 90m while working on the roof of an apartment building. The height, s, in meters, of the hammer after t seconds can be modeled by...
-
The highest temperature during the cycle in vapour compression refrigeration system occurs after (a) compression (b) condensation (c) expansion (d) evaporation
-
Cronin, an employee of Epicycle, cashed his final paycheck at Money Mart Check Cashing Center. Epicycle had issued a stop payment order on the check. Money Mart deposited the check through normal...
-
Power Drive Corporation designs and produces a line of golf equipment and golf apparel. Power Drive has 100,000 shares of common stock outstanding as of the beginning of 2024. Power Drive has the...
-
On 1 January 20x6, Company X acquires the entire share capital of $500,000 comprising of 500,000 ordinary shares in Company Y. Retained earnings as that date amounted to $100,000. In previous years,...
-
Prepare a Brief long Report on the brand "Evive" You have to make a brief report on Evive! They are amazing, they are pre-frozen smoothie packs that you can use to make a smoothie without a blender!...
-
Describe how costs are allocated under the direct method, the step method, and the algebraic method.
-
Design a creative advertising strategy to increase participation in Little League Baseball.
-
Go to a high school sporting event, college sporting event, and professional sporting event. At each event, interview five spectators and ask them why they are attending the events and what benefits...
-
Discuss, in detail, the major objectives of sports sponsorship from the perspective of the sponsoring organization.
-
What two decisions do advertisers make in developing a media strategy? What are the four basic media scheduling alternatives? Provide an example of each type of media scheduling.
-
Calculate the principal stresses for the following 2D - stress state. xx = 125 MPa, yy =-200 MPa and Txy = 125 MPa. Calculate the principal stresses for the following 3D - stress state. Units = MPa...
-
What is the role of business risk analysis in the audit planning process?
-
Pittsburgh-Walsh Company, Inc. (PWC), manufactures lighting fixtures and electronic timing devices. The lighting fixtures division assembles units for the upscale and mid-range markets. The trend in...
-
Describe at least three benefits that an organization can expect to realize from budgeting.
-
Shateau Job Shop had the following operating data for its operations in 2010: Budgeted fixed overhead .............$20,000 Standard variable overhead application rate ...... $3 per MH Fixed overhead...
-
What are some of the advantages of equity financing?
-
Does a company share its risk by issuing equity or debt?
-
A minor league professional hockey team embarks on an aggressive facility expansion that requires additional capital. Management decides to finance the expansion by borrowing \($40\) million and by...
Study smarter with the SolutionInn App