Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Jython Output Help! (Simple question)

$
0
0
Hey guys!

So I am trying to do a program, and for the most part I have it down except for 1 part of it.

Basically, we are to to write a single function, which will continue to prompt a user to enter an integer number between 1 and 100 inclusive, until the user enters a invalid integer.

I have the program here:

def assign2PartB(): 
  x = 0
  while x <= 100: 
    x = input ("Enter a number between 1 and 100 to continue: ")
    printNow ("The number you entered was: " + str(x))
    if x <=0:
      printNow ("The number you entered (" + str(x) + ") was not between 1 and 100. Try again, please!")


And the output is as followed:
>>> assign2PartB()
Enter a number between 1 and 100 to continue: 19
The number you entered was: 19
Enter a number between 1 and 100 to continue: 99
The number you entered was: 99
Enter a number between 1 and 100 to continue: 0
The number you entered was: 0
The number you entered (0) was not between 1 and 100. Try again, please!

My question is, when I enter "0" how do I get my program to not show "The number you entered was: 0" but only show "The number you entered (0) was not between 1 and 100. Try again, please!"

Thanks so much in advance guys, I appreciate your help!

Viewing all articles
Browse latest Browse all 2703