473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Jython output help (beginner question)

2
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, I want my function to 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:
Expand|Select|Wrap|Line Numbers
  1. def assign2PartB(): 
  2. x = 0 
  3. while x <= 100: 
  4. x = input ("Enter a number between 1 and 100 to continue: ") 
  5. printNow ("The number you entered was: " + str(x)) 
  6. if x <=0: 
  7. 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!
Feb 2 '13 #1
2 3025
bvdet
2,851 Expert Mod 2GB
You need to put "printNow ("The number you entered was: " + str(x))" in an if/elif/else block. Example:
Expand|Select|Wrap|Line Numbers
  1. def assign2PartB(): 
  2.     while True: 
  3.         x = input("Enter a number between 1 and 100 to continue:") 
  4.         if x < 1: 
  5.             print "The number you entered (%s) was not between 1 and 100. Try again, please!" % (x)
  6.         elif x > 100:
  7.             print "The number you entered was: %s" % (x)
  8.             print "Exiting!"
  9.             return
  10.         else:
  11.             print "The number you entered was: %s" % (x)
  12.  
  13. assign2PartB()
  14.  
Feb 2 '13 #2
od11kd
2
Thank you so much! Appreciate it
Feb 4 '13 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt Newcomb | last post by:
G'day, Hi, I've got a java class called ChannelIteratorAlgorithm which extends SampledChannelGroupIteratorAlgorithm. SampledChannelGroupIteratorAlgorithm has a stub method...
46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
3
by: Neal | last post by:
managed C++ VS 2003 I have a beginner question about windows forms.... I need to call a function when a certain limit has been reached, now with the way VS sets up the .NET windows Form I get...
1
by: Mark Fink | last post by:
Hi there, unfortunately I am new to Jython and my "Jython Essentials" book is still in the mail. I looked into the Jython API Doc but could not find the information. I am porting a Python...
3
by: tomrobin | last post by:
Hi, I'm having trouble with data types. I understand that the double data type is 64-bit, which should correspond to 15 digits(?). However, it seems from running this program that it can only...
8
by: AG | last post by:
Hello, This is my first post to this group, and on top of that I am a beginner. So please direct me to another group if this post seems out of place.... I have recently written a program which...
6
by: Andy Leese | last post by:
Beginner Question: ASCII Symbols I am using Borland C++ and programming under DOS. I wish to display the symbols of the early ASCII character set... For example: cout << char(7); ...
0
by: Daniel T. | last post by:
Carter <cartercheng@gmail.comwrote: When you see "discards qualifiers", more often than not, it means that a const object is begin asked to do something that only non-const objects can do....
2
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.