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
Here is my code
import time
print("------------------------------------------")
print(" Welcome to Senpai Quest")
print('------------------------------------------')
time.sleep(3)
print("")
print('You have English next, there is a test. If you hit yes .you go to
class and you get +1 charisma and Knowledge.')
print("")
print('If you hit no, you will skip class and get +1 Courage and +1 risk.')
ans1=str(input('Do you Take the english test? [Y/N]'))
if ans1== ['y']:
print("It works")
else:
print("Woo Hoo!")
When it asks the question and for the 'y' it just goes straight through to "woo hoo!". What i would like it to do is to print "It works" but if you type n it just goes to woo hoo. Please help
This should work:
ans1 = input('Do you Take the english test? [Y/N]').strip()
if ans1.lower() == 'y':
print("It works")
else:
print("Woo Hoo!")
I suggest using the distutil's strtobool in order to cover all cases
from distutils.util import strtobool
ans1=input('Do you Take the english test? [Y/N] ').strip()
if strtobool(ans1):
print("It works")
else:
print("Woo Hoo!")
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 1 year ago.
Improve this question
def main_menu():
print("WELCOME TO LIBRARY")
print("What would you like to do?")
option=print(input("1. New user \n 2. Existing user ")
if option == 1:
new_user()
elif option == 2:
old_user()
else:
print("please choose a correct value")
main_menu()
def new_user():
print("new user")
def old_user():
print("Old user")
main_menu()
Here is a picture of the error, it says syntax error missing ")" for function call and missing "else" for the first one at "if":
the line
option=print(input("1. New user \n 2. Existing user ")
is missing a closing )
it should be
option=print(input("1. New user \n 2. Existing user "))
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
while True:
inp = raw_input()
if inp == "":pres= input("What would you like to know about me? AGE, JOKE, FACT")
if pres in {'AGE'}:
print("I was birthed from my mother 87 years ago.")
if pres in {'JOKE'}:
print("Where do polar bears keep their money?")
import time
time.sleep(2)
print("In a snow bank!")
if pres in {"FACT"}:
print("Hippopotamus's have pink spit!")
I am a student and for my school project have to do a code and for some reason I can't figure out how to get the chatbot to answer the question when someone puts in AGE, JOKE or FACT. Insteas, it just repeats the question when I press enter.
You are asking for input in your while True loop. It will never exit, because True is... always true. You need to put the if statements inside the loop for them to execute as well.
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 5 years ago.
Improve this question
I'm having trouble with this code. It will run normally until it gets to the loop (def Game) and just stops there. I did have it as an if statement but that still didn't work. Please note that this may be a bit messy.
import random
import time
GameInProgress = ("Yes")
TutorialDone = ("No")
ReplayGame = ("Yes")
#Test purposes
PlayerName = ("Lewis")
print ("Welcome to 'Guess The Word!")
def Game():
GameInProgress = ("Yes")
TutorialDone = ("No")
ReplayGame = ("Yes")
#Test purposes
PlayerName = ("Lewis")
print ("Welcome to 'Guess The Word!")
WordSelected=("No")
LettersGuessed=0
print (TutorialDone)
EnterName = input("Would you like to enter your name?").title()
def Game(): is not a loop, it is a function it does not execute until you call it.
you can call a python function in this way
Game()
if you want to call the same function again and again simply you can call the function inside a for or while loop:
while(condition):
Game()
if your are very beginner follow some tutorials
https://www.tutorialspoint.com/python/python_functions.htm
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 5 years ago.
Improve this question
Hi i am am trying to make a program where if you enter hi it will say you rule but if you enter anything else it will say sucker
my current code is
import sys
print("enter your password")
pword = (sys.stdin.readline())
if pword == "hi"
print("i rule")
else:
print("sucker")
please help!
just add strip to remove unwanted space/newline characters
import sys
print("enter your password")
pword = (sys.stdin.readline())
if pword.strip() == "hi":
print("i rule")
else:
print("sucker")
Use this instead:
pword = input()
Or if it's Python 2.x, use raw_input() instead.
But fix your indentation first, and add a colon after if pword == "hi".
no need to import sys(except you want to)
pword = input("enter your password")
if pword == "hi":
print("i rule")
else:
print("sucker")
If you want to the correct code is:(you forgotten an : in the if statment)
import sys
print("enter your password")
pword = (sys.stdin.readline())
if pword.strip() == "hi":
print("i rule")
else:
print("sucker")
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
name=input("Hello person, Whats your name?")
print("Hello", name)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
print("Ok", name,", listen up")
print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
choice2=input("What do you want to call the house?")
print("The old,",choice2,"was once owned by an old lady. ")
elif choice==("maybe"):
print("You found an easter egg, congrats. PS this does nothing")
Whats wrong with this code?? It says in the idle shell syntax error. The last elif statement isn't working.
This is a petty indentation issue, your print statements for the if blocks are not indented right and so the elif seems to be out of place. Note that python keeps track of logical blocks by the indentation.
name=input("Hello person, Whats your name?")
print("Hello", name)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
print("Ok", name,", listen up")
print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
choice2=input("What do you want to call the house?")
print("The old,",choice2,"was once owned by an old lady. ")
elif choice==("maybe"):
print("You found an easter egg, congrats. PS this does nothing")
As already pointed out, if choice==("yes" or "yes " or "Yes" or "Yes ") is wrong, use if choice.lower().strip() == "yes" instead, or if choice in ("yes", "yes ", "Yes", "Yes ").
If in case this is python 2, input will throw an error, use raw_input instead.
Also print with multiple statements will throw errors as well if used like a function, so change them from print(statement_x, statement_y, statement_z) to print statement_x, statement_y, statement_z