[Tutor] Tutor Digest, Vol 169, Issue 20
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Mar 26 18:21:45 EDT 2018
First of all, please do not repost the entire digest - we have
all already seen them - and some people pay by the byte.
Secondly...
On 26/03/18 21:44, David Brown wrote:
> Thanks Joel. That got me going in the right direction. I ended up using a
> "while true" statement. The code below seems to work now. It will accept
> any key and not just "Y". Haven't gotten that far with it yet.
How do you exit the loop?
Your code as it stands just ignore the users input completely.
You may as well miss out the line.
That's why Joel suggested a check, so that the user can quit
nicely.
> while True:
> input(" \n\tHit ENTER to see your fortune")
> number = random.randint (1,6)
> if number == 1:
> print("\n", prefix,"When much wine goes in very bad things come
> out.")
> count += 1
> elif number == 2:
> if count > 5:
> print("\nNo more fortunes for you")
> break
> if count <5:
So you have to do it 5 times, even if you don't want to?
> input("\n\nEnter 'Y' if you would like another fortune: ")
> continue
This ignores the user's response.
If you really want a while True loop then might I suggest
restructuring to something like:
while True:
if input("Had enough yet? ").lowercase[0] == 'y':
break # exit the loop
# continue with the original if/elif tree here
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list