469,301 Members | 2,282 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

Very beginner in Python : If/else statement

Hello,
I tried to make a simple program that interacts with the user and asks about his gender. However, I cannot seem to make it work past line 7. Could someone help me please ? Thanks a lot :)

print ("Hello, nice to meet you. What's your name ?")
name = input()
print ("Hi, " + name)
print ("That's a beautiful name.")
print ("As for me, my name is Ali, I am a boy.")
print ("Are you a boy as well ?")
while True:
prompt1 = input()
if prompt1 == "yes":
print("Hey bro")
elif prompt1 =="no":
print ("Hi sis")
else:
print ("Huh")
4 Weeks Ago #1
2 7145
dev7060
501 Expert 256MB
Hello,
I tried to make a simple program that interacts with the user and asks about his gender. However, I cannot seem to make it work past line 7. Could someone help me please ? Thanks a lot :)

print ("Hello, nice to meet you. What's your name ?")
name = input()
print ("Hi, " + name)
print ("That's a beautiful name.")
print ("As for me, my name is Ali, I am a boy.")
print ("Are you a boy as well ?")
while True:
prompt1 = input()
if prompt1 == "yes":
print("Hey bro")
elif prompt1 =="no":
print ("Hi sis")
else:
print ("Huh")
I added the indentation and it seems to be working fine (python 3). What isn't working for you?
Expand|Select|Wrap|Line Numbers
  1. print ("Hello, nice to meet you. What's your name ?")
  2. name = input()
  3. print ("Hi, " + name)
  4. print ("That's a beautiful name.")
  5. print ("As for me, my name is Ali, I am a boy.")
  6. print ("Are you a boy as well ?")
  7. while True:
  8.     prompt1 = input()
  9.     if prompt1 == "yes":
  10.         print("Hey bro")
  11.     elif prompt1 =="no":
  12.         print ("Hi sis")
  13.     else:
  14.         print ("Huh")
3 Weeks Ago #2
bulieme
2 2Bits
To reduce line.
Also '\n' is a string break for python, you can called it 'enter'.

Expand|Select|Wrap|Line Numbers
  1. print ("Hello, nice to meet you. What's your name ?")
  2. name = input()
  3. print("Hi, " + name+ "\n That's a beautiful name.  \n As for me, my name is Ali, I am a boy.\n Are you a boy as well ?")
  4. while True:
  5.     prompt1 = input()
  6.     if prompt1 == "yes":
  7.         print("Hey bro")
  8.     elif prompt1 =="no":
  9.         print ("Hi sis")
  10.     else:
  11.         print ("Huh")
  12.  
2 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by hanumizzle | last post: by
2 posts views Thread by paul | last post: by
2 posts views Thread by juan-manuel.behrendt | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.