In the code below, the problem seems to be on line 16. What happens is that when I run the code, no errors occur, but when I want to type something, for some reason the only thing that the code says is "What is your name?", which is not supposed to happen. What I think the problem is is that the hi and the hello and all that is somehow being read in my input, even when I input a space and nothing else. What am I doing wrong and what do I have to do to fix it? Thanks!
#!/usr/bin/env python
# -*- coding: utf8 -*-
from random import randint
print "Hello! My name is Bob."
text = raw_input("Type here: ").lower()
f = False #False boolean
t = True #True boolean
a = t #Variable 1
p = "" #Previous input
pb = "" #Previous Bob output
while True:
if a == t:
if " hi " or " hello " or " hai " or " hey " in text:
print "What is your name?"
text = raw_input("Type name here: ").lower()
a = f
elif "/stop" in text:
asdfasdadsfsdf
elif "fine" in text or "good" in text or "gr8" in text or "great" in text:
print "Good!"
text = raw_input("Type here: ").lower()
a = f
elif "that name is stupid" in text or "that's dumb" in text or "you're dumb" in text:
print "Just like you, m8. OoooOOOoooOOOOOoo"
text = raw_input("Type here: ").lower()
a = f
elif "my name is" or "my name's" in text and pb == "What is your name?":
p = text
print("hello %s" % p)
text = raw_input("Type here: ")
a = f
else:
print "What?"
text = raw_input("Type here: ")
a = f
else:
if " hi " or " hello " or " hai " or " hey " in text:
print "What is your name?"
text = raw_input("Type name here: ").lower()
a = t
elif "/stop" in text:
asdfasdadsfsdf
elif "fine" in text or "good" in text or "gr8" in text or "great" in text:
print "Good!"
text = raw_input("Type here: ").lower()
a = t
elif "that name is stupid" in text or "that's dumb" in text or "you're dumb" in text:
print "Just like you, m8. OoooOOOoooOOOOOoo"
text = raw_input("Type here: ").lower()
a = t
elif "my name is" or "my name's" in text and pb == "What is your name?":
p = text
print("hello %s" % p)
text = raw_input("Type here: ")
a = t
else:
print "What?"
text = raw_input("Type here: ")
a = t
Aucun commentaire:
Enregistrer un commentaire