I'm trying to write a python script that achieves the following:
- First, prompt a user to enter the username or press enter to exit.
- Prompt a user to enter quantity.
- Next, use regular expression to make sure that the username consists of 5 to 10 alphabetical characters.
- Use regular expression to make sure that quantity consists of only numerical values and the quantity entered is between 0 and 100
- If both the username and quantity are valid, then print the username and quantity. Otherwise print an error message.
Finally, prompt the user for username again or press enter to exit.
import re, sys username = "" username = input('Enter Username (Press ENTER to exit): ') while username != "": quantity = input('Enter Quantity: ') if re.match("[a-zA-Z]{5,10}$", username) and re.match("[0-9]{1,2}$", quantity) and type(quantity) is int and quantity > 0: print('Username: ', username, "\n" 'Quantity: ', quantity) else: print('Error: Enter a username consisting of 5-10 alphabetical letters and a valid integer between 1 and 100') username = input('Enter Username (Press ENTER to exit): ')How would I achieve these requirements? When I run my program I always print the error message and can't properly print the username and quantity. Thank you for taking the time and I appreciate any help I can get.