Corrective action
You should make an attempt to correct errors or offer alternatives.
Example: Corrective action 1
Test 3.1 failed
def validateName(): '''A function to validate and return name''' valid = False #flag to start loop while not valid: name = input('Please enter your name: ') if name !='' and len(name)<=20: and not any(char.isdigit() for char in name): #presence, length & type check print('Welcome ()'.format(name)) valid = True #break the loop return nameThe original code could not detect when a user entered digits instead of letters for their name. This resulted in a data typeDefines the sort of data that a variable can hold – String, Integer, Real, Boolean or Record (user defined structure). error (program was expecting a string, but received an integer).
This was corrected by extending the validation rule in line 7.
The isdigit() method (a method that returns true if any character is a digit) was used to go through the name variable and check that no digits are in the name variable.
Result:
Please enter your name: Suzy7
Please enter your name: Suzy
Welcome Suzy
Please select the level of difficulty from the menu below:
1. Easy
2. Medium
3. HardThe code now checks if any character in the name is a digit. If a digit is entered, the name will not be accepted and the user is asked to enter their name again.
You are expected to test all functions within your code and record the results.