Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

Repeating in Python

aricmiller
aricmiller

Hello, world! I am currently working on a AI and I would like to repeat the code,

if UserInput == "hi": print(AI_Name + ": Hello!") elif UserInput == "who made you": print(AI_Name + ": I was made by Aric Miller") if UserInput == "who are you": print(AI_Name + ": I'm " + AI_Name + "! I can do lots of things.")

But I am not sure how to do that. Could you help me?
Thanks in advance!
-Aric Miller (

@aricmiller
)

2 years ago
You are viewing a single comment. View All
1
Coder100
Coder100

Try this code:

while True UserInput = str.lower(input("") if UserInput == "hi": print(AI_Name + ": Hello!") elif UserInput == "who made you": print(AI_Name + ": I was made by Aric Miller") if UserInput == "who are you": print(AI_Name + ": I'm " + AI_Name + "! I can do lots of things.") if UserInput == "what time is it" or "what is the time" or "time": print(AI_Name + ": " + ".")

remember to indent lol!

also, this code will always be true:

if UserInput == "what time is it" or "what is the time" or "time":

that's because python makes it

if (UserInput == "what time is it") or ("what is the time") or ("time"):

a string is always true, so this will always be true.

so change it to

if UserInput in ("what time is it", "what is the time", "time"):
2 years ago
1
aricmiller
aricmiller

@Coder100
Thanks! It's still giving me an error at line 18 though.

2 years ago