Error Checking Practice
1) Write a program using try/except to ensure that the datatype of the inputted data is correct
Create your own input prompts and error messages.
-Ask a user to enter four numbers
-Output the average of the numbers.
2) Write a program that calculates the sum of the first n integers as shown below.
Make sure your program does two error checks:
1) checks datatype of input
2) checks that the integer entered is > 0
Your program should loop until the user enters an appropriate number
Suggested Sample Program Interaction:
This program will add up all the numbers from 1 until the number you enter.
Enter number: mmm, Oreo cookies... my favourite!
Invalid input! Please enter a positive integer greater than 0!
Enter number: 10
The sum of the first 10 integers is 55.
3) Write a program that calculates the average for an unknown number of temperatures.
Repeatedly ask for input until the user enters “Done”.
Make sure your program checks for data type – are there any additional checks?
#Sample run:
Enter the temperature: -14.3
Enter the temperature: 34
Enter the temperature: -6
Enter the temperature: Done
The average temperature is 4.6 degrees Celsius.
For the last two questions, design your own sample interactions and error messages.
4) Ask the user for a positive integer and calculate the factorial of that integer.
5) Ask the user for a positive integer and calculate the factorial of that integer.
This time, make sure the integer is not less than 0 and no greater than 50.
(0 and 50 may be valid inputs)