Question: PYTHON LOOPS I need help with Questions 7,8,9 and 10. For number 7, i'm unsure what the error is so please help with that as
7. Provide comments for the following code: (5 points) \#Assigns the value 0 to a new variable called total. total =0 \#Assigns the value 0 to a new variable called count. count =0 \#Asks for user input of an item price, casts it to fioat, but will skip while loop when price is 0 . price = float (input ("Enter the price of iten (0 when done) : ")) ARuns loop body when price float was set to pos tive values, breaks out of loop when price entered is 0 . \#Precondition, price >=0. while price > ot \#increments the count of items by 1 . count = count +1 \#increments the total variable by the recorded price float. total += price \#Asks for user to update the value of price, or set to 0 when all items and prices are accounted. price = float (input (nenter the price of item (0 when done): ) )) \#Prints the total price as a String. print ("Total is: \$" + str (total)) \#Prints the total number of items accounted for in the while loop. print ("Number of items is. ", oount) Prints the average price by dividing the total price by the number of items. print ("Average price is: ", total ( count) The above code raises an error in a special case. 8. What is the error? ( 1 point) If a user inputs a negative value, the code will return an error because it will assume The average price as 0/0 and will crash Python since that is not possible. 9. What is the error type? (1 point) It is a runtime/exception error with ZeroDivisionError because if someone inputs a negative value, the console will print 0/0. 10. How do you prevent it? Write the part of the code that corrects it. (1 point) ng code accounts egative or aneous inputs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
