'Pretty basic problem, just trying to print() text after code block regardless of previous code
I am new to coding and I am trying to have a statement printed after my code, with other print() in the code block. I think I am having a problem with the indentation or I am not using the >>> or ... correctly
After the code I want it to say "move on" post what the code decides:
>>> age = 19
>>>if(age>18):
print("go through")
elif(age==18):
print("go see pink floyd")
else:
print("go to meat loaf")
print("move on")
So I would like it to say
"go through" or "go to pink floyd" or "go to meatloaf" and then say "move on"
so if age is 19
go through
move on
if age is 18
go to pink floyd
move on
if age is 17
go to meatloaf
move on
but I keep getting a syntax error on based on my final print statement.
>>> age=19\
>>> if(age>18):\
print("go through")\
elif(age==18):\
print("go see pink floyd")\
else:\
print("go to meat loaf")\
print("move on")
SyntaxError: invalid syntax
Syntax error on the print("move on") statement If I use the print statement in the else statement as follows:
>>> age=19\
>>> if(age>18):\
print("go through")\
elif(age==18):\
print("go see pink floyd")\
else:\
print("go to meat loaf")\
print("move on")
go through
I do not get the "move on" but it will work if the age<18 I want the the "move on" statement to be printed after the if, elif, else statement regardless.
I have also tried:
>>> age=19\
>>> if(age>18):\
print("go through")\
elif(age==18):\
print("go see pink floyd")\
else:\
print("go to meat loaf")\
>>> print("move on")
SyntaxError: invalid syntax\
So thank you for taking time to look at this, who ever that may be. I know its simple, but I greatly appreciate the help. I also tried some other version of the placement of the print statement and the "...print("move on"), but still get a syntax error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
