How does one answer this question. 1. A dramatic society wants to record the number of tickets sold for each of their four performances. Ask the user to enter the number of tickets sold for each performance. The number must be between 0 and 120. Print an error message if an invalid number is entered and ask them to re-enter until they enter a valid number. Print the total number of tickets sold and the average attendance for a performance.
import re
affirm = False
p = 0
total = 0
for p in range(4):
p = input("Please enter the total number of tickets sold for the performance.")
while affirm != True:
try:
int(p)
except ValueError:
print("This is not a number")
else:
valid = re.match("[0-120]",p)
if valid:
total += p
affirm = True
else:
p = input("Please enter the total number of tickets sold for the performance.")
average = (total/480) * 100
average = round(average,2)
print("""
The total number of tickets sold is: """,total"""
The average attendance is : """,average)
My python book didn't really explain the correct syntax for the re module and the try except else function. Can someone point out if there is anything wrong with the code. This was my first go at validating user input.