On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron <a...@phpandmore.net> wrote: > On 10/02/17 04:33, adam14711...@gmail.com wrote: >> Hello, >> >> My computer programming professor challenged me to figure out a way >> to manipulate my program to display one error message if the user >> input is a zero or a negative number, and a separate error message if >> the user input is a decimal number. My program starts out: [snip] > The function int(str) raises the exception ValueError if the input > string does not represent an integer. > > Use: > > try: > num=int(str) > except ValueError e: > print "Error: not an integer"
What should happen if the user types "1.0"? To be flexible about this possibility, you could accept the number as a float, and then complain if int(num) != num. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list