Sometimes, the users of your program do not input exactly what you expect. Perhaps you ask them to put in a positive number, but they may input a negative number on accident. Worst case scenario: this breaks your program!
Write a program called `positivenumber.py` that uses a while loop to repeatedly ask the user to enter a positive number and says “Thanks!” once they did and “Oops! Try again.” if they did not.
-!- CODE language-text -!-Please enter a positive number: -9
Oops! Try again.
Please enter a positive number: 0
Oops! Try again.
Please enter a positive number: 4
Thanks!
CodeGrade is your virtual teaching assistant in your Python classroom. You teach, CodeGrade takes care of the rest.
Our 35 built-in fully automatically graded Introduction to Programming assignments are designed especially for middle school and high school coding education, in close collaboration with Harvard-Westlake School (Los Angeles, CA). You can start teaching Python at your school with confidence now. Or, easily scale your classroom with CodeGrade's tools.
Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!