Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm new to Python and while trying to write a scrip that will keep asking questions about the user until the scrip gets FALSE,
I decided to check the scrip,of course it gave me an syntax error that told me the mistake was on the fifth lane, `a.
Now on that lane I tried to change the old value of a to a new value.
sadly, I can't understand the mistake that I made, can some one please check it and explain me what went wrong ?
#!/usr/bin/python
print "Hello, I'm wilfred and I'm an Artificial Intelligence\n"
a=str(raw_input("Do you want to be my friend? \n"))
if a=="yes":
a=str(raw_input("Yey ! my first friend,what is your name?\n"))
if a==str :
print "Nice name man!"
elif a==int :
print "bye!"
elif a=="no":
print "Well, nice to meet you anway, good bye now \n"
Your line
a=str(raw_input("Yey ! my first friend,what is your name?\n")
Indent this line so it is inside the 'if' statement
Add a ')' at the end of this line
You just need to indent the line. Your code should work fine. Keep learning python. It's awesome!!!!
#!/usr/bin/python
print "Hello, I'm wilfred and I'm an Artificial Intelligence\n"
a=str(raw_input("Do you want to be my friend? \n"))
if a=="yes":
a=str(raw_input("Yey ! my first friend,what is your name?\n"))
if a==str :
print "Nice name man!"
elif a==int :
print "bye!"
elif a=="no":
print "Well, nice to meet you anway, good bye now \n"
To further help with the test cases, I changed your string and int tests for you. "==" test is for value btw.
#!/usr/bin/python
print "Hello, I'm wilfred and I'm an Artificial Intelligence\n"
a=str(raw_input("Do you want to be my friend? \n"))
if a=="yes":
a=str(raw_input("Yey ! my first friend,what is your name?\n"))
if a.isalpha() :
print "Nice name man!"
elif a.isdigit() :
print "bye!"
elif a=="no":
print "Well, nice to meet you anway, good bye now \n"
A general structure for this kind of repeating loop is
while True:
a=str(raw_input(...))
if a=="whatever": break
# other responses to a
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So, I'm just starting to try to learn Python and I'm following a "book" called: Automate the Boring Stuff with Python. I'm doing the first program in the book and I thought things were going just fine...but now I'm getting an error and I'm unable to figure out why.
# This Program says hello and ask for my name.
print('Hello world!')
print('What is your name?') # ask fo their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName)
print('What is your age?') # ask for thier age
myAge = input()
print('You will be ' +str(int(myAge) + 1) + ' in a year.')
VS Code shows errors starting around line 9 but I can't for the life of me figure it out. Any help would be greatly appreciated.
Thanks.
print(len(myName)
Missing ')'.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
When I try to run my code it says I have invalid syntax with my else statement, but I can't figure out what's wrong.
import random
import time
username = input("Hello. Please enter your name, then press 'enter'.
After you type something, you will need to /n"
"click the 'enter' key to send it")
print ("Hello " + username)
time.sleep(3)
game_tutorial_input = input("Do you wish to see the tutorial? (y/n)")
if game_tutorial_input == "y":
print ("Great! Press enter after each instruction to move /n"
"onto the next one.")
else
print("Are you sure? (y/n")
indent matters in python , make sure the else is on the same indent column as the if. and as stated you need a : at the end of else.. ie, else:
Try 'else:'
I believe it's missing a colon.
indent out the else
add a colon to end of the else
Explanation:
else, if, elif, with etc.. are statements which need colons after the statement
add colon after else and indentation of else is wrong
if game_tutorial_input == "y":
print ("Great! Press enter after each instruction to move /n"
"onto the next one.")
else:
print("Are you sure? (y/n")
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Hello I'm a noob and just started using python so I wanted to have fun using raw_input , adding random questions and stuff but I came across an error. It says the invalid syntax is ". I've been trying to put it to different places but didnt succeed I'm sorry if this is a really dumb question but can someone help me out.
Heres a line with the error
print " Oh okay then %s . You came from %s , right? Oh i see you came here to %s" % (name,so,fun)
It's pointing at the closing " next to %s
I'm using atom
edit: heres the error
File "C:\Users\USER\AppData\Local\atom\app-1.26.1\Testing.py", line 10
print " Oh okay then %s . You came from %s , right? Oh i see you came here %s. " % (name, so, fun)
^
SyntaxError: invalid syntax
Heres the full code :
name = raw_input("Hello whats your name?")
so = raw_input("From where did you come from")
fun = raw_input("Interesting, why did you come here?")
#start the sentence with "for"
print " Oh okay then %s . You came from %s , right? Oh i see you came here %s. " % (name, so, fun)
If I can't use raw_input what can I use then? I learned with using that.
I fixed the issue by putting brackets around the whole thing like
print (" Oh okay then %s . You came from %s , right? Oh i see you came here to %s" % (name,so,fun))
Also I believe that raw_input was replaced with 'input()'.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
def cave():
global key
global response
print(''' You find yourself standing infront of a cave.
You venture into the cave to find a large door blocking
your path.
(insert key, turn around''')
response = input("Enter a command: ")
while response != 'insert key' or response != 'turn around':
if response =='insert key' or response == 'turn around':
break
print('Choose one of the options: ")
response = input()
if response == 'insert key':
if key == 1:
win()
else:
print('''You don't have a key. Get One!!''')
elif response == 'turn around' :
home()
That's almost always caused by mixing tabs and spaces. Check your file contents with an editor that can show you this, such as by using :set list in vi.
But you may also want to look at this line:
print('Choose one of the options: ")
You're starting your string with one quote type and ending it with another, which is valid is neither Python 2 nor 3.
Once I'd fixed that and ensured that indentation was correct, it worked fine for me. I had to add a mainline that called cave() but it ran without error albeit not doing much useful since I don't have any of the rest of your code.
If you are using Notepade+ or VIM then check where is the tabs and space.
Also make sure that string you started must be end with same character. If you start with '(Single quote) then end with same.
print('Choose one of the options: ")
Ablove line start with ' but end with ". That will give you syntext error.
The indent block may cause by when you paste the code, before the code is 4 blanks (not in ascii), the python cannot read it , you can delete it and add a 'tab'.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
the python idle is throwing a error at the print() function im not sure why heres the code..
password = "cow"
name = input()
input("MR PENGUIN: hello there i am Mr Penguin what is your name? ")
input("well, hello there"+name+"Tell me your password")
input("You: my password is, ")
input("MR PENGUIN: im little defh could you repeat that? ")
input("YOU: my password is, "
print("PC POLICE: STOP! dont ever trust penguins with your data becuase he just told every one that your password is "+ password)
input("Press Enter To Exit")
You are missing a parenthesis at the end of the input on the prior line.
Change:
input("YOU: my password is, "
to:
input("YOU: my password is, ")
For the record, your print was fine. Note that when you get a cryptic error, it is often something on the previous line.
This is because your input statement in the previous line is missing a closing paranthesis.
It should be:
input("YOU: my password is, ")
instead of
input("YOU: my password is, "