69.8k views
2 votes
Write a function definition for a function named getNumber, which uses a reference parameter to accept an integer argument. The function should prompt the user to enter a number in the range of 1-100. The input should be validated and stored in the parameter variable.

1 Answer

5 votes

Final answer:

Here is a function definition for the getNumber function that prompts the user to enter a number in the range of 1-100 and stores the validated input in a reference parameter.

Step-by-step explanation:

getNumber Function Definition



Here is the function definition for the getNumber function:



def getNumber(num: int) -> None:
while True:
try:
num = int(input('Enter a number in the range of 1-100: '))
if num<1 or num>100:
raise ValueError
break
except ValueError:
print('Invalid input. Please enter a number between 1 and 100.')



This function uses a reference parameter num to accept an integer argument. It prompts the user to enter a number in the range of 1-100 and continuously validates the input until a valid number is entered. The validated number is then stored in the num parameter variable.

User Ant Radha
by
8.3k points