Python line not running [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 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.

Related

Working on a python project and there are syntax errors never faced before [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 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 "))

How to stop infinite loop in simple chatbot [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 1 year ago.
Improve this question
I have a simple chatbot with the following code
import random
human_input = input('Talk to me: ')
continue_dialogue = True
greeting_inputs = ("hey", "good morning", "good evening", "morning", "evening", "hi", "whatsupp")
greeting_responses = ["hey", "hey hows you?", "*nods*", "hello, how you doing", "hello", "Welcome, I am good and you"]
def generate_greeting_response(input):
for token in input.split():
if token.lower() in greeting_inputs:
return random.choice(greeting_responses)
while continue_dialogue:
for token in human_input.split():
if generate_greeting_response(human_input) is not None:
print("Chatterbot: " + generate_greeting_response(human_input))
input('Talk to me again: ')
else:
print("Chatterbot: Bye")
continue_dialogue = False
What I wanted was that if human_input is recognized inside greeting_inputs for the conversation to keep going and if it isn't, then the conversation would stop. But the code above never stops the conversation even if I input nonsense. Why is my else statement never activating?
Update input('Talk to me again: ') to
human_input=input('Talk to me again: ')
Since next time it asks, you haven't given it a variable to assign the input, it keeps repeating

Python is stopping before running a loop [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 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

Python - How do I get this to read the code? [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 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!")

Why does my <a> and <b> if conditional not execture when a and b are both True? [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
EDIT: It was a typo on my part. I couldn't see the lack of parantheses after GetEventObject for some reason.
Code:
def onKeyDown(self, event):
ESC_list = [self.topic_control,self.search_control]
print event.GetEventObject() in ESC_list
keycode = event.GetKeyCode()
print keycode == wx.WXK_ESCAPE
if keycode == wx.WXK_ESCAPE and event.GetEventObject in ESC_list:
print "fire"
self.onExit(event)
event.Skip()
When I run tests where both print statements give me "True" the if conditional doesn't execute. What gives?
You're missing a pair of parentheses:
if keycode == wx.WXK_ESCAPE and event.GetEventObject() in ESC_list:
# ^^ HERE
Your current code is syntactically valid, but has different semantics. It checks whether the function object itself -- and not the result of calling the function -- is present in ESC_list.

Categories

Resources