Monday, July 1, 2019

Conditionals Revisited in Python

 So two days ago I decided to jump right into Python. I decided to re-code the conditionals thing in Python because it'd be a good exercise. Here's the code for it.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
weekend = input("Is it the weekend? (Yes/No) ")
busy = input("Are you busy? (Yes/No) ")
str_time = input("What time is it? (Enter a whole number between 0 and 23) ")
time = float(str_time)
woke = input("Did you wake up? (Yes/No)")

if weekend == "Yes" or weekend == "yes":
    if busy == "No" or busy == "no":
        if 0 < time < 11:
            if woke == "Yes" or woke == "yes":
                print("Go back to sleep. You earned it.")
            if woke == "No" or woke == "no":
                print("Continue sleeping. It's the weekend.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if 11 <= time < 24:
            if woke == "Yes" or woke == "yes":
                print("You can be productive for a bit longer.")
            if woke == "No" or woke == "no":
                print("You slept early, didn't you? That's good.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response to awake. Please start over.")
        if time < 0 or time > 24:
            print("You have entered an invalid response. Please start over.")
    if busy == "Yes" or busy == "yes":
        if 0 < time < 11:
            if woke == "Yes" or woke == "yes":
                print("Great, now get to it! You've got stuff to do!")
            if woke == "No" or woke == "no":
                print("What are you doing? Get up! You've got stuff to do!")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if 11 <= time < 24:
            if woke == "Yes" or woke == "yes":
                print("Hopefully you've been working. You've got stuff to do!")
            if woke == "No" or woke == "no":
                print("If you don't get your lazy butt out of bed, I will pop out of the program and wake you up.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if time < 0 or time > 24:
            print("You have entered an invalid response. Please start over.")
    if busy != "Yes" and busy != "yes" and busy != "No" and busy != "no":
        print("You have entered an invalid response. Please start over.")
if weekend == "No" or weekend == "no":
    if busy == "No" or busy == "no":
        if 0 < time < 11:
            if woke == "Yes" or woke == "yes":
                print("It's the weekday. You probably have stuff to do. Go get groceries.")
            if woke == "No" or woke == "no":
                print("You can sleep in, but it's a weekday. Be mindful.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if 11 <= time < 24:
            if woke == "Yes" or woke == "yes":
                print("Definitely don't go back to sleep. It's the weekday.")
            if woke == "No" or woke == "no":
                print("Seriously get a job or go to college if you can afford to sleep in this late.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if time < 0 or time > 24:
            print("You have entered an invalid response. Please start over.")
    if busy == "Yes" or busy == "yes":
        if 0 < time < 11:
            if woke == "Yes" or woke == "yes":
                print("Great, now get to it on this fine weekday! You've got stuff to do!")
            if woke == "No" or woke == "no":
                print("What are you doing? Get up! It's the weekday and you've got stuff to do!")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if 11 <= time < 24:
            if woke == "Yes" or woke == "yes":
                print("Getting started with the work early? Good job.")
            if woke == "No" or woke == "no":
                print("I hope you work second or third shift because otherwise you're SUPER late.")
            if woke != "Yes" and woke != "yes" and woke != "No" and woke != "no":
                print("You have entered an invalid response. Please start over.")
        if time < 0 or time > 24:
            print("You have entered an invalid response. Please start over.")
    if busy != "Yes" and busy != "yes" and busy != "No" and busy != "no":
        print("You have entered an invalid response. Please start over.")
if weekend != "Yes" and weekend != "yes" and weekend != "No" and weekend != "no":
    print("You have entered an invalid response. Please start over.")

No comments:

Post a Comment