Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Organization / Getting Started Create a project4 folder somewhere on a flash drive, onedrive or on your computer. Name your main python file retailcost-yourlastname.py,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Program Organization / Getting Started Create a project4 folder somewhere on a flash drive, onedrive or on your computer. Name your main python file retailcost-yourlastname.py, and use your real last name. The main function in retailcost-yourlastname.py should consist of a single function definition, main, and a single call to main. Also in the retailcost-yourlastname.py file and ABOVE the main function, and still inside retailcost- yourlastname.py you must include a definition for the following function: a function to calculate and return the retail cost, this function will receive two values from variables containing wholesale cost and markup percentage NOTE: Only your main() function in retailcost-yourlastname.py should print the results; the function above main should only compute value of the retail cost and return it to the main() function. The final form of the supporting function should not print anything, but only return values. The following is the general form of the program to be written: #retail_cost() function defined here compute and return retail cost def maino: #read in the information using the input() function and convert it to into a float type variables # call the retail_cost() function passing it the two variables needed to compute retail_cost #print out the retail cost #print out the required end of project message return 0 # main function successful end main() # calls the main function LLI A . . . Getting the Numbers It is usually good to start small. The first step in getting a project to work is to start with the correct structure. Python looks at the indention of your code to determine what is part of a function. Everything that is indented underneath def maino: is considered to be part of our main() function. Here is how to get one of the two numbers and store it into a variable (Python code is blue/ comments are green): def maino: # get wholesale cost from user string_wholesale = input("Enter the wholesale cost, numbers and decimal only: ") # convert the string into a float value and store it into the variable: wholesale wholesale = float( string_wholesale ) # confirm the information entered back to the user print("You entered a wholesale cost of: ", wholesale ) print() # skip a line to show it completed successfully #the main() function should return return 0 Place the above code inside the main function, and remember that unless the main function is called, it will not run -- be sure you have an OUT-DENTED line below the main function to call it as: main() # calls the main function Run your program in the Thonny editor by clicking the arrowhead to run programs on the toolbar or hitting the F5 key. After you get this working, continue with the next steps to create a function to calculate retail cost. Creating a Function to Calculate Retail Cost At this point we already have a main() function that is in control of our program. The main() function calls all other functions. The start of these project instructions explains that calculating retail cost requires the wholesale cost and the markup percentage. We have a complete module on functions later in the class, but since functions are used so much in Python it is good to get a little experience with them now. Here is how to create (define) a function that receives one of the two values (also known as formal parameters of the function): def retail_cost( wholesale_cost): return 0 Everything that is part of the retail_cost function must be indented, this is the way Python knows what is part of the function. If we were to outdent, the un- indented code would not be part of the function. The retail_cost function's code MUST be placed ABOVE the start of the main() function's definition, that means ABOVE the line: def main(): Next, in order for the retail_cost() function to actually be RUN the main(function must be modified to CALL the retail_cost function, and so we can see what is returned by the function, a print() statement is added to display it in the lower Thonny shell window: def maino: # ... other code to get numbers with input() is here # call the retail_cost() function retail = retail_cost( wholesale ) # show the retail cost computed at this point print("The retail cost is: ", retail) # the main() function should return 0 to show it completed successfully return 0 Run your program in the Thonny editor by clicking the arrowhead to run programs on the toolbar or by hitting the F5 key -- you should see the program print the message "The retail cost is:0" when it runs at this point. After you get this working, continue to modify your retailcost-yourlastname.py file (see the Stepwise Refinement section below) Stepwise Refinement Follow these steps for a stress-free time developing the project: 1. Implement the program as suggested in the Getting the Numbers and Creating a Function .. sections -- make sure that the message: "The retail cost is:0" is printing at this point in the development process. 2. Modify main() function in your retailcost-yourlastname.py so that it asks for the markup percentage needed for the project using the already created code that captures the wholesale cost as a pattern. 3. Modify the retail cost() function so that it defines a second formal parameter for the markup percentage and correctly computes and returns the retail cost instead of just returning 0. This will require modification to the the function definition line: def retail_cost( wholesale_cost ): as well as the line with return O. The line with return 0 will instead need to calculate the retail cost using the wholesale_cost and markup_percentage. The calculation will be some form of retail cost equals wholesale cost multiplied by one plus the markup percentage, you will need to transform this PSEUDOCODE into a valid Python mathematical expression! 4. Modify main() function in your retail cost-yourlastname.py so that the call to the retail_cost function includes the second item to be passed (the markup percentage ) in the function call, that will require modification of the line: retail = retail_cost( wholesale ) Note: the second item will need to be inside the parentheses with a comma between wholesale and the the second item. 5. Finally, print the end of project message: "End of Retail Cost, Project 4 by your first and last name" inside the main() function before it returns 0 Note: You must use your REAL first and last names. Programs that do not include the real first and last name will receive a point deduction

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

Students also viewed these Databases questions