0
Why doesn’t this code work
import datetime import os class BOPA: def __init__(self, des): self.des = des class Shutoffpcs(BOPA): def ID(self): os.system("shutdown/i") class Date(BOPA): def ID(self): date_object = datetime.date.today() print(date_object) SOPCS = Shutoffpcs("1") DATE = Date("3") while True: ip = input(": ") if ip == "shutdown other pc" or "Shutdown other pc": SOPCS.ID() elif ip == "what is the date today" or "What is the date today": DATE.ID() This code keeps giving me the shutdown option when I’m trying to use the date one. Pls help
2 odpowiedzi
+ 3
Try changing this
while True:
ip = input(": ")
if ip == "shutdown other pc" or "Shutdown other pc":
SOPCS.ID()
elif ip == "what is the date today" or "What is the date today":
DATE.ID()
To
while True:
ip = input(": ")
if ip == "shutdown other pc" or ip == "Shutdown other pc":
SOPCS.ID()
elif ip == "what is the date today" or ip == "What is the date today":
DATE.ID()
I think the problem is in the if-elif conditions.
+ 1
When you want to check that a variable is one of several possible values, you can also use the 'in' operator
if var in ('this', 'that', 'something'):