$29.99
Reading
Read Chapter 5 and 6.4 in Introduction to Computing using Python: An Application Development Focus, Second Edition by Ljubomir Perković.
Logistics
You need to do this assignment on a computer which has Python 3 installed on it. Python 3.8.5 download page can be found here.
A submission that includes code which does not run will not get any points for the part unless specifically documented reason of the error.
Assignment
1. (30pt) while loop
You've been keeping track of your planned bank account transactions, and it doesn't look so good, e.g. you had the following transactions in the list lst. Positive values are incoming money, negative values are money spent.
order of value, that is largest negative transactions get eliminated first, until you reach a positive budget. Write a program improve(lst) which implements that strategy and prints the remaining transactions as well as the overall resulting budget. If this is not possible (if you're only spending money), the program should warn you about that.
2. (70pt) Infinite loop/Loop-and-a-half and exceptions
a. (30pt) Implement a function guess(n) that takes an integer as a parameter and implements a simple, interactive guessing game. The function should start by choosing a random number in the range from 1 up to and including n. The function should then repeatedly ask the user to enter to guess the chosen number. When the user guesses correctly, the function should print a message to congratulate the user and terminate. Each time the user guesses incorrectly, the function should indicate whether the guess was too high or too low. If the user types something other than an integer, the function should recover gracefully.
b. (40pt) Write a program add() that keeps prompting the user for numbers until they simply hit return. At that point, the program should return the sum of all numbers entered by the user. If user enters something other than a number, prompt the user to enter a number. See test-runs below.
Hint: use try/except for wrong user inputs.
Submission
Submit the assignment using Assignment 4 folder. Submit only a single python file using your name as file name (e.g. Jay_Tang_Assign_4.py).