Code the following using Python3 A popular internet-based DVD rental company is
ID: 3755815 • Letter: C
Question
Code the following using Python3
A popular internet-based DVD rental company is buying up everyone’s used DVDs. They want you to create a program that makes sure the DVDs they buy are decent and sold to them at a good price. Your program should first ask how many times a movie has been watched, then it should ask how much money they want to sell this movie for, and finally it should ask what genre of movie it is. The user must enter valid information for each input, and the program must re-prompt the user as many times as needed until they enter valid input for each question. Once they enter valid values for all three questions, the program should display the times watched, price, and genre as entered by the user. You can assume that the type of input will be correct for each question asked, but you must validate the value entered. If the user enters an invalid input, the program must tell the user why it is invalid: for watches, whether it is too high or low; for price, whether it is too high or low or not divisible of 0.25; for genre, that it must be ‘romance’, or ‘comedy’ to be accepted. The input must be validated to these specifications: • Times watched must be between 0 and 10, inclusive. • Price must be: o Between 0 and 15, inclusive, and o Divisible by 0.25 (so 1.25, 2.50, 5.00, 10.75, etc. are all accepted) • Genre must be ‘romance’, ‘comedy’, in all lowercase. HINT: You should be using constants for at least some of these integer and string values! HINT: You can use floating point numbers with the modulus operator! Test this out in the interpreter before you use it.
Explanation / Answer
Here is the code
---------------------------------------------------------------------------------------------------------
invalid=True
time_watched=-1
while invalid:
time_watched = int(input("how many times a movie has been watched? : "))
if time_watched<0:
print("Time watched cannot be less than 0")
elif time_watched>10:
print("Time watched cannot be greater than 10")
else:
invalid=False
invalid=True
price=-1
while invalid:
price = float(input("how much money they want to sell this movie for? : "))
if price<0:
print("Price is too low")
elif price>15:
print("Price is too high")
elif (price*100)%25 !=0 :
print("Price not divisible by 0.25")
else:
invalid=False
invalid=True
genre=""
while invalid:
genre = input("what genre of movie it is ? : ")
if genre=="romance" or genre=="comedy":
invalid=False
else:
print("Genre should be either romance or comedy")
print("You entered : "," Times Watched : ", time_watched," Price you want to sell : $",price," Genre type : ", genre)
Here are couple of output samples
-------------------------------------------------------------------------------------------
how many times a movie has been watched? : 9
how much money they want to sell this movie for? : 15
what genre of movie it is ? : romance
You entered : Times Watched : 9 Price you want to sell : $ 15.0 Genre type : romance
how many times a movie has been watched? : -1
Time watched cannot be less than 0
how many times a movie has been watched? : 11
Time watched cannot be greater than 10
how many times a movie has been watched? : 5
how much money they want to sell this movie for? : -1
Price is too low
how much money they want to sell this movie for? : 16
Price is too high
how much money they want to sell this movie for? : 12.77
Price not divisible by 0.25
how much money they want to sell this movie for? : 12
what genre of movie it is ? : r
Genre should be either romance or comedy
what genre of movie it is ? : comedy
You entered : Times Watched : 5 Price you want to sell : $ 12.0 Genre type : comedy