Discussion:
[Tutor] Help with else
Nick Brodsky
2015-10-09 03:31:17 UTC
Permalink
name = raw_input("What is your name")

print "Great! Now %s, are you a boy or a girl?" % (name)

gender = raw_input("")

if gender == "boy":
print " I can see that, you are very strong":
if gender == "girl":
print ' Yes, and a beautiful one':
else:
print "Your choice"


I don't understand why it doesn't work, it just skips over the else. Thanks for

the help!


Montreallisting.ca
Free Montreal Classifieds


Gaminggame.com
Best Game Reviews You'll Find
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-10-09 09:21:17 UTC
Permalink
Post by Nick Brodsky
name = raw_input("What is your name")
print "Great! Now %s, are you a boy or a girl?" % (name)
gender = raw_input("")
print "Your choice"
I don't understand why it doesn't work, it just skips over the else.
Not for me it didn't, it gave an error.

Please always post exactly what the program produces
don't try to summarize.

In this case there are several potential errors but the first
thing to fix are the colons after the print statements. You
only need colons on the end of control statements such as
for, while, if/else etc.

The second thing that I see is that although (I assume)
you only want the 'your choice' to print if the user
selects something other than boy/girl it will print
even for boy. That's because the boy section is in
a separate if statement.

Like this simplified snippet:

if boy: print....

if girl: print...
else: print...


But I think you wanted

if boy: print...
elif girl: print ...
else: print...

Can you see the difference in logic?

HTH
--
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


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Enes Unal
2015-10-09 09:07:19 UTC
Permalink
may be this one?

name = raw_input("What is your name")

print "Great! Now %s, are you a boy or a girl?" % (name)

gender = raw_input("")

if gender == "boy":
print " I can see that, you are very strong"
elif gender == "girl":
print ' Yes, and a beautiful one'
else:
print "Your choice"
Post by Nick Brodsky
name = raw_input("What is your name")
print "Great! Now %s, are you a boy or a girl?" % (name)
gender = raw_input("")
print "Your choice"
I don't understand why it doesn't work, it just skips over the else. Thanks for
the help!
Montreallisting.ca
Free Montreal Classifieds
Gaminggame.com
Best Game Reviews You'll Find
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Continue reading on narkive:
Loading...