473,324 Members | 2,417 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,324 software developers and data experts.

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")
Sep 18 '21 #1
2 7982
dev7060
633 Expert 512MB
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")
Sep 22 '21 #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.  
Oct 6 '21 #3

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

Similar topics

18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
17
by: hanumizzle | last post by:
I have used Perl for a long time, but I am something of an experimental person and mean to try something new. Most of my 'work' with Vector Linux entails the use of Perl (a bit of a misnomer as it...
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
5
by: clear1140 | last post by:
Good day!! I was wondering if it is possible to put an if else statement inside a where clause of an sql statement... you see i would like my update statement to do this: update...
2
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a...
4
by: maveri4201 | last post by:
I have written a php script (test3.php), which I attached as a text file. Its includes are also attached as text files. I'm trying to run the script here: http://www.wondergy.com/phptestbed/test3.php...
2
by: Robert Ingles | last post by:
I apologize for my current lack of knowledge and hope that someone will be kind enough to give me some additional help.I posted a question regarding "Record does not exist, open add record form". I...
1
by: Joshua Billings | last post by:
I am working on a programming assignment, and I can't figure out what is wrong with these lines of code. if ad > 6: rectAD.setFill("red") if ad <= 3: rectAD.setFill("red") else: ...
4
by: tastingoo | last post by:
Hi, I'm having problems accessing the worksheet after creating the worksheet in an IF statement. For some reason, if I create the worksheet in the else statement, my $rxsheet address is gone...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.