jeudi 18 juin 2020

If and elif statement are being ignored. Goes straight to the else statement Python

I am trying to conduct a very basic mini quiz but I keep running into an issue where only my else statement is being fulfilled & I'm not sure as to why?

        userSleep = [input("Please enter 1 or 2 to answer the question. ")]
        if userSleep == 2:
                print("Thank you for your answer")
                time.sleep(1)
                print("What would you say stops you from getting more sleep?")
                print("[1.] Social Media")
                time.sleep(.25)
                print("[2.] On-demand TV services (i.e Netflix, Crunchyroll, YouTube etc.)")
                time.sleep(.25)
                print("[3.] Medically diagnosed insomnia")
                time.sleep(.25)
                print("[4.] School assignments/coursework")
                time.sleep(.25)
                print("[5.] Other")
                time.sleep(.5)
                userHabits = [input("Please enter a number corresponding one of the options above to answer the question. ")]
                print("Thank you for your answer")
                time.sleep(1)
                break
                clear()
        elif userSleep == 1:
                print("Thank you for your answer")
                time.sleep(1)
                break
                clear()
        else:
                print("Please input either a 1 or 2")```

I'm using Python 2.7

Aucun commentaire:

Enregistrer un commentaire