Question
The following steps will be completed and submitted via a Microsoft word file. Any other format will not be accepted and will result in a
The following steps will be completed and submitted via a Microsoft word file. Any other format will not be accepted and will result in a zero grade:
1. Test and debug a variation of the Test Scores Program. a. In IDLE , open the test_scores.py file. b. Review the code. c. Create a test plan that thoroughly tests the program with valid data. This can be handwritten table or a spreadsheet that includes the test data for three or four test runs as the expected results. d. Use your test plan as a guide to test the program. Then, note any inaccurate results that you discover during testing. e. Debug any logic errors. f. Test the program with the same data to be sure it works correctly.
2. Trace the operation of the calculate_future_value() function of a Future Value Program. You will also use the IDLE shell to test the functions in this program.
a. Use print() functions to trace the execution of a function.
i. In Idle, open the future_value.py file.
ii. Test the program and note that the future value results are obviously inaccurate. In fact, the calculate_future_value() function has two logic errors.
iii. To debug this problem, scroll down to the calculate_future_value(), and add print() functions that show you how the values of the variables change each time through the loop.
iv. Run the program and review the results.
v. Fix the errors and comment out the print() function that you added. b. Use the idle shell to test the functions of this program.
i. Run the Future Value Program to make sure its functions are loaded into the shell.
ii. Test its three functions. This shows you how easy it is to test a function without running the entire program.
3. Step through the Future Value Program using IDLE Debugger. a. Step through the calculate_future_value() function.
i. In IDLE, open the future_value.py file updated file from Step
2. ii. In the calculate_future_value() function, set a breakpoint on the first executable statement. Then, go the IDLE shell and start the debugger. That should display the debug Control window. Now, check the Source checkbox.
iii. Try to arrange the editor, shell, and Debug Control windows so you can see all there. That should make it easier for you to switch from one window to another and to see what's happening.
iv. Go to the editor and run the program. That should take you to the Debug Control Window. Then, click Go to run the program to the break point, and enter the required values when prompted in the interactive shell.
v. At the breakpoint, click the Step button to step through the function and note how the values of the local variables change. When you see how this works, click the Quit button to the end the debugging session. When you see how this works, click the Quit button to the end the debugging session.
b. Step through the entire program. i. In the editor window, remove the breakpoint in the calculate_future_value() function and set a breakpoint on the first statement of the main module. Then, run the program to the breakpoint as before.
ii. Step through the program. This should take you from the main() function of the function that it calls. This may also take you to Python functions that will not make much sense to you, you can step out of them right away. In short, experiment with the Step, Over, and Out buttons as you step through the code.
iii. When you are through experimenting, click on the Quit button to end the session.
#!/usr/bin/env python3 # display a welcome message print("The Test Scores application") print() print("Enter test scores") print("Enter 'x' to end input") print("======================") # initialize variables counter = 0 score_total = 0 test_score = 0 while True: test_score = input("Enter test score (or 'x' to quit): ") if test_score != "x": test_score = int(test_score) #counter += 1 else: break if test_score >= 0 and test_score <= 100: score_total += test_score counter += 1 else: print("Test score must be from 0 through 100. Score discarded. Try again.") # calculate average score average_score = round(score_total / counter) # format and display the result print("======================") print("Total Score:", score_total, " Average Score:", average_score) print() print("Bye") #!/usr/bin/env python3 def get_number(prompt, low, high): while True: number = float(input(prompt)) if number > low and number <= high: is_valid = True return number else: print("Entry must be greater than", low, "and less than or equal to", high, "Please try again.") def get_integer(prompt, low, high): while True: number = int(input(prompt)) if number > low and number <= high: is_valid = True return number else: print("Entry must be greater than", low, "and less than or equal to", high, "Please try again.") def calculate_future_value(monthly_investment, yearly_interest, years): # convert yearly values to monthly values monthly_interest_rate = yearly_interest / 12 months = years * 12 # calculate future value future_value = 0.0 for i in range(1, months): future_value += monthly_investment monthly_interest = future_value * monthly_interest_rate future_value += monthly_interest return future_value def main(): choice = "y" while choice.lower() == "y": # get input from the user monthly_investment = get_number("Enter monthly investment:\t", 0, 1000) yearly_interest_rate = get_number("Enter yearly interest rate:\t", 0, 15) years = get_integer("Enter number of years:\t\t", 0, 50) # get and display future value future_value = calculate_future_value( monthly_investment, yearly_interest_rate, years) print() print("Future value:\t\t\t" + str(round(future_value, 2))) print() # see if the user wants to continue choice = input("Continue? (y/n): ") print() print("Bye!") if __name__ == "__main__": main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started