Learning coding and "While True" usage is giving an error [closed] - python

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 6 years ago.
Improve this question
So, I am trying to learn Python and am using Python 3.6.0a3 on windows 10. As part of my practice I was trying to use the "while" loop and the editor says there is an error with my code and the cursor goes to 'While True"
My code is:
#Program to practice While and Continue
While True:
Print('Who are you?')
name=input()
If name!='Joe':
continue
print('Hello Joe! What is the password? (It is a fish)')
password-input()
If password=='swordfish'
break
print('Access granted')
I can't execute it!

Here's a working example:
#Program to practice While and Continue
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello Joe! What is the password? (It is a fish)')
password = input()
if password == 'swordfish':
break
print('Access granted')
You had a bunch of syntax errors:
Python is case-sensitive, so if, while and print should all be in lower-case.
Conditional statements need to end with a colon :
Statements inside a conditional block need to be indented.
Further reading:
https://www.python.org/dev/peps/pep-0008/

Related

Why doesn't input return a the print value with .lower() or .upper() commands? [closed]

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 11 months ago.
Improve this question
When i run the code my python doesn't recognize what i put in whether it's with .lower or .upper, why is that?
import sys
Good = input('Am i Good? > ').upper()
if Good == 'no':
print(True, 'You are good')
elif Good == 'no':
print(True, ' You are still good')
elif Good == 'quit':
sys.exit()
In this line of code:
Good = input('Am i Good? > ').upper()
You transform the input to uppercase, but then you compare the string with lowercase strings ("no", "quit"). This will never match since "NO" and "no" are different strings (Python cares about case when comparing strings).

Getting a Syntax Error in python with first program [closed]

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 ')'.

Invalid syntax with else statement in python3 [closed]

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")

Python, syntax error using "if, elif" [closed]

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

python idle 3.4.0 'print' syntax error [closed]

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, "

Categories