1. getValidInput will perform and validate user input. It has no parameters. It prompts the user to...
Fantastic news! We've Found the answer you've been seeking!
Question:
1. getValidInputwill perform and validate user input. It has no parameters. It prompts the user to enter a float value between 0 and 100, boundaries included. As long as the value entered is not valid, the prompt for a valid value wil be repeated. Thevalid valueentered will bereturnedby the function as a float value.
- Call the function in an assignment statement (such asvalidNumber = getValidInput()) and print out the value of the variablevalidNumber.
- Test the function by entering different values.
- Enter a negative value,
- Enter a value greater than 100,
- Enter the value 0.
- Enter the value 100.
- Enter a value between 0 and 100. (not 0, not 100).
2. diceAverage Write a value-returning function without parameters that simulates rolling a dice (with six numbers) for 1000 times and then calculates and returns the average of all numbers rolled. Use therandint()function of the random module for rolling the dice.
- Call the function three times. Is the average always the same?
Tips
- You need to import the random module in your program. After the three comment lines, start your code as follows:
import random
- When using therandint()function, the arguments must be 1 and 6.
num = random.randint(1,6)
Posted Date: