Odd syntax Error that I do not know how to fix - python

I was creating a program in python 3 that asks your name, age, and a password. I am getting a syntax error and I do not know why.
Here is my code:
import time
needCheck = False
check = ("Just to check")
myName = ("Mason")
myAge = (12)
thePassword = ("Potatos are gud")
print("...")
time.sleep(3)
print("Scanning")
time.sleep(3)
print("*HUMAN_LIFEFORM DETECTED*")
time.sleep(2)
print("Greetings inhabitant of planet Earth")
name = input("What is your name, Earthling?")
if name == myName:
print("Oh, it's you")
needCheck = True
else:
print("Salutations, " + name + "!")
if needCheck:
age = input(check + ", " "what is your age?")
if age == myAge:
print("Looking good so far...")
else:
print("You're not fooling me anymore...")
needCheck = False
else:
age = input("What is your age " + name + "?")
if age == myAge:
print("Hmmm...")
if needCheck:
pass = input(check + "again" + ", " + "what is the super secret password?")
if pass == thePassword:
print("I knew it was you!")
else:
print("You must be an imposter! Where is the real Mason?!")
else:
pass = input("What is the super secret password, " + name + "?")
if pass = thePassword:
print("How did you know that?!")
print("Self Destruct In:")
time.sleep(1)
print(3)
time.sleep(1)
print(2)
time.sleep(1)
print(1)
while True:
print(BOOM)
time.sleep(0.5)
IDLE says the error is in this line, on the equals sign:
pass = input(check + "again" + ", " + "what is the super secret password")
If you know why it is invalid syntax, please answer.
Thanks!

pass is a reserved word. try using any other word and it should work

Related

I want my python code to restart if variable contain is "No" [duplicate]

This question already has answers here:
How do I repeat the program in python [duplicate]
(2 answers)
Closed 2 years ago.
nameQuestion = "Whats ur name?"
print(nameQuestion)
name = input()
ageAuestion = "How old r u?"
print(ageAuestion)
age = input()
print("Your name is: " + name + " " + "age: " + age + "?(yes or no)")
answer = input()
if answer == "Yes":
print("Name: " + name + ", " + "Age: " + age)
else:
print("Error")
I need to restart code if answer == "no". How i can do it
This will do:
while True:
nameQuestion = "Whats ur name?"
print(nameQuestion)
name = input()
ageAuestion = "How old r u?"
print(ageAuestion)
age = input()
print("Your name is: " + name + " " + "age: " + age + "?(yes or no)")
answer = input()
if answer == "Yes":
print("Name: " + name + ", " + "Age: " + age)
break
else:
print("Error")
continue
While Doc
use while True and put a check when you want to break out of while loop.
while True:
`your code`
.
.
`condition to break out of while loop`
Use a while loop:
answer = ''
while answer != 'yes':
nameQuestion = "Whats ur name?"
print(nameQuestion)
name = input()
ageAuestion = "How old r u?"
print(ageAuestion)
age = input()
print("Your name is: " + name + " " + "age: " + age + "?(yes or no)")
answer = input()
print("Name: " + name + ", " + "Age: " + age)
while True:
nameQuestion = "Whats ur name?"
print(nameQuestion)
name = input()
ageAuestion = "How old r u?"
print(ageAuestion)
age = input()
print("Your name is: " + name + " " + "age: " + age + "?(yes or no)")
answer = input()
answer = answer.lower()
if answer == "yes":
print("Name: " + name + ", " + "Age: " + age)
break
else:
pass
You can use while loop
You can do something like this:
wrong_data = True
while wrong_data:
name = input("Whats ur name?")
age = input("How old r u?")
answer = input(f"Your name is {name} and your age is {age}?(yes or no)")
# you should put answer.lower so both 'yes' and 'Yes' are interpreted correctly
if answer.lower() == "yes":
print(f"Name: {name}, Age: {age}")
wrong_data = False

Replace expected at least 2 arguments got 1 error

Hello I got some stuck in my code and I tried but I still don't know how to fix it. Here it's my code.
def staff_info (name):
print ("So you are " + name + ", years old. ")
name = input ("Type your name: ")
confirm_info = input ("So you have " + name + ". Confirm that? (Yes/No) ")
if confirm_info == "Yes":
print ("Okay so I have few more question for you. ")
else:
confirm_info == "No"
change_info = input ("So what do you want to change? ")
if change_info == "name":
name_change = input ("Type the name you want to change: ")
name = name.replace (name_change) #error here
...
else:
...
print ("So you are " + name + ", " + age + " years old. You have over " + result_experience1 + " with code.")
If you could explain it and give me a command to solve it, I'd appreciate it. My adventure with Python beginning last week from now. Thanks you.
Thereplace method takes two mandatory parameters:
The substring you want to replace
The new value
So, change this
name = name.replace (name_change)
to
name = name.replace(name, name_change)
More here
You can try this:
def staff_info(name):
print("So you are " + name + ", years old. ")
name = input("Type your name: ")
confirm_info = input("So you have " + name + ". Confirm that? (Yes/No) ")
if confirm_info == "Yes":
print("Okay so I have few more question for you. ")
elif confirm_info == "No":
change_info = input("So what do you want to change? ")
if change_info != name:
name_change = input("Type the name you want to change: ")
new_name = name_change.replace(name, name_change)
print("New Name = ", new_name)
else:
print("...")

I need help in while loop for this program

So I'm trying to create a while loop so the user can choose whether they want to continue the program or not. Any suggestions?
import random
while True:
print ("--------------------------------------------------------------------\n")
name = input("Please enter your name: ")
pack = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
random.shuffle(pack)
print ("Welcome {0}! Hope you have fun playing! \n".format(name))
print("Original deck:", pack, "\n")
print ("--------------------------------------------------------------------\n")
for i in range(3):
pack1 = pack[::3]
pack2 = pack[1::3]
pack3 = pack[2::3]
print("1: ", pack1, "\n")
print("2: ", pack2, "\n")
print("3: ", pack3, "\n")
user = input("Pick a number and enter the row it is in: ")
while not (user == "1" or user == "2" or user == "3"):
print(user, " is not a valid answer. Please try again \n")
user = input("Pick a number and enter the row it is in: ")
if user == "1":
pack = pack3 + pack1 + pack2
elif user == "2":
pack = pack1 + pack2 + pack3
elif user == "3":
pack = pack2 + pack3 + pack1
print("The number you are thinking of is:", pack[10], "\n")
answer = input("Would you like to play again (y/n)? ")
if answer != "y" or answer != "n":
break
print ("Please press 'y' or 'n' and then Enter... ")
if answer == "y":
continue
else:
print ("Thank you for playing!")
break
Just to bring in some context about what this is about, this is a 21 Cards Trick program. Try it out if you want.
Edit: Also what's happening when the question at the end is asked is that it's not really restarting the program when you type 'y'.
Use a control boolean to handle the status of the user involvement.
Also your while loop indentation was incorrect, as Vasilis G. pointed out.
import random
controlFlag = True #add boolean control
while controlFlag == True:
print ("--------------------------------------------------------------------\n")
name = input("Please enter your name: ")
pack = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
random.shuffle(pack)
print ("Welcome {0}! Hope you have fun playing! \n".format(name))
print("Original deck:", pack, "\n")
print ("--------------------------------------------------------------------\n")
for i in range(3):
pack1 = pack[::3]
pack2 = pack[1::3]
pack3 = pack[2::3]
print("1: ", pack1, "\n")
print("2: ", pack2, "\n")
print("3: ", pack3, "\n")
user = input("Pick a number and enter the row it is in: ")
while not (user == "1" or user == "2" or user == "3"):
print(user, " is not a valid answer. Please try again \n")
user = input("Pick a number and enter the row it is in: ")
if user == "1":
pack = pack3 + pack1 + pack2
elif user == "2":
pack = pack1 + pack2 + pack3
elif user == "3":
pack = pack2 + pack3 + pack1
print("The number you are thinking of is:", pack[10], "\n")
answer = input("Would you like to play again (y/n)? ")
if answer == "y":
controlFlag = True # unnecessary, left in for completeness.
elif answer == 'n':
print ("Thank you for playing!")
controlFlag = False
else:
print('wrong choice')
break
General main loop structure usually goes somewhat like this:
def func():
while True
#run your game or whatever
#ask for input somehow
if input==truthy:
break
func()

Ask a Q based on a generated number in python 3.5

I am making a conversation simulator and am trying to make randomly generated questions, this is the code I have.
import time
print ("Hello")
time.sleep(2)
age = input("How old are you?")
time.sleep(2)
if age.isdigit() and age >= str(0):
print ("Ok, cool I am " + age + " too.")
time.sleep(2)
yourname = input("What is your name again?")
print ("Cool, " + yourname + " is a nice name")
time.sleep(2)
name = input("Do you remember my name?")
print ("Ya my name is " + name + " you got it")
from random import randint
print(randint(0,4))
elif randint = 1
print ("hello")
elif randint = 2
print ("hello")
elif randint = 3
print ("hello")
elif randint = 4
print ("hello")
elif randint = 5
else:
print ("ERROR")
I am trying to ask a random question from a random integer value.
I honestly cannot find out what is wrong and I am still learning python 3.5.

Can't fix "TypeError: 'str' object is not callable" in Python

I need help fixing the error. Here is my code:
import random
def game():
capitals={"England":"London","France":"Paris","Belgiom":"Brussels",\
"Canada":"Ottawa","China":"Beijing","Cyprus":"Nicosia",\
"Cuba":"Havana","Egypt":"Cairo","Greece":"Athens",\
"Ireland":"Dublin","Italy":"Rome","a":"A","B":"B"}
wrong=[]
right=[]
incorrect_answers = False
while len(capitals)>0:
pick = random.choice(list(capitals.keys()))
correct_answer = capitals.get(pick)
print ("What is the capital city of" + pick + "?")
answer = input("Your answer: ")
if answer.lower() == correct_answer.lower():
print ("That's Correct!\n")
del capitals[pick]
right.append(pick)
else:
print ("That's Incorrect.\n")
print ("The correct answer is" + correct_answer + "\n")
wrong.append(pick)
incorrect_answers = True
del capitals[pick]
print ("You got ",len(right), "/", len(wrong))
top = len(right)
bottom = len(wrong)
perc = float((top / bottom) * 100)
print(perc)
if incorrect_answers:
print ("Here are the ones that you may want to brush up on:\n")
for each in wrong:
print (each)
else:
print ("Perfect!")
def help():
print("do you neeeded efhdufghaf dfgjn")
while True:
input = input("what do you want to do? help or play?")
if input == "help":
help()
break
if input == "play":
print("you want to play")
game()
break
You shouldn't do this
input = input("what do you want to do? help or play?")
You are shadowing the function input with your variable. Change the name of your variable to something else.

Categories