import datetime
import sys
start_time = datetime.datetime.now()
def bitbox ():
print ("Hitting the drum")
i = input ("Did you call Siri?"[Yes/No]")
ifi == "Yes":
print ("I'm listening...")
input ("Enter=>")
Ifi == "What time is it?" or "What time is it?" or "Tell me the current time." or "What time is it?" or "What time is it?"":
print(start_time)
ifi == "Try beatboxing":
print ({bitbox})
elifi == "No":
print ("I see")
sys.exit()
I wrote this code. Please enter my intention I wanted to make it work if I typed "What time is it?" and "Try beatboxing" later. But even if I keep typing "Try beatboxing", the time is printed out. I'd appreciate your help.
input def if문
First of all, Python is a language that requires good indentation.
The code you wrote won't work as intended because you don't follow those rules well.
If you've corrected those parts well, the most important problem to be solved after that is that there are no variables that store the values entered through input("Enter=>")
.
If you write it as above, i
is i = input ("Did you call Siri?"You will only save the values you entered in [Yes/No]")
.
That's why the output statement for the bitbox is not executed.
But the reason why time is printed is because
ifi == "What time is it?" or "What time is it?" or "Tell me the current time." or "What time is it?" or "What time is it?":
This is because the conditional statement does not cause errors and is an invalid code.
Conditional statements are what people intuitively think
Writing a == 1 or 2 or 3
does not mean comparing a with all 1, 2, and 3.
You have to compare them one by one so that the computer can understand them.
It's a simple part, so I think it's better to study Python grammar properly and make it again.
© 2024 OneMinuteCode. All rights reserved.