-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPart 2 - More Conditionals.py
196 lines (164 loc) · 4.85 KB
/
Part 2 - More Conditionals.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#| a | b | a and b | a or b |
#| ----- | ----- | ------- | ------ |
#| False | False | False | False |
#| True | False | False | True |
#| False | True | False | True |
#| True | True | True | True |
#| a | not a |
#| ----- | ----- |
#| True | False |
#| False | True |
# Python allows for a simplified way of expressing 'x >= a and x <= b' as 'a <= x <= b'
# Example 1
n1 = int(input("Number 1: "))
n2 = int(input("Number 2: "))
n3 = int(input("Number 3: "))
n4 = int(input("Number 4: "))
if n1 > n2 and n1 > n3 and n1 > n4:
greatest = n1
elif n2 > n3 and n2 > n4:
greatest = n2
elif n3 > n4:
greatest = n3
else:
greatest = n4
print(f" {greatest} is the greatest of the numbers.")
# Example 2
name = input("Please type in your name: ")
if name == "Huey" or name == "Dewey" or name == "Louie":
print("I think you might be one of Donald Duck's nephews.")
elif name == "Morty" or name == "Ferdie":
print("I think you might be one of Mickey Mouse's nephews.")
else:
print("You're not a nephew of any character I know of.")
#| points | grade |
#| ------ | ----------- |
#| < 0 | impossible! |
#| 0-49 | fail |
#| 50-59 | 1 |
#| 60-69 | 2 |
#| 70-79 | 3 |
#| 80-89 | 4 |
#| 90-100 | 5 |
#| \> 100 | impossible! |
# Example 3
point = int(input("How many points [0-100]: "))
if point > 100 or point < 0:
grade = "impossible!"
elif point <= 49:
grade = "fail"
elif point <= 59:
grade = 1
elif point <= 69:
grade = 2
elif point <= 79:
grade = 3
elif point <= 89:
grade = 4
elif point <= 109:
grade = 5
print(f"Grade: {grade}")
# Example 4
number = int(input("Number: "))
mod3 = number % 3
mod5 = number % 5
if mod3 == 0 and mod5 ==0:
print("FizzBuzz")
elif mod3 == 0:
print("Fizz")
elif mod5 == 0:
print("Buzz")
# If-Statement Leap Year
year = int(input("Please type in a year: "))
# First, we make assumption that a year is not a leap year
leap_year = False
if year % 100 == 0:
if year % 400 == 0:
leap_year = True
elif year % 4 == 0:
leap_year = True
if leap_year:
print("That year is a leap year.")
else:
print("That year is not a leap year.")
# Alphabetically in the middle - 1
first = input("1st letter: ")
second = input("2nd letter: ")
third = input("3rd letter: ")
if first > second:
if first < third:
print(f"The letter in the middle is {first}")
elif second > third:
print(f"The letter in the middle is {second}")
else:
print(f"The letter in the middle is {third}")
elif first < second:
if first > third:
print(f"The letter in the middle is {first}")
elif second < third:
print(f"The letter in the middle is {second}")
else:
print(f"The letter in the middle is {third}")
# Alphabetically in the middle - 2
letter1 = input("1st letter: ")
letter2 = input("2nd letter: ")
letter3 = input("3rd letter: ")
if letter1 > letter2 and letter1 > letter3:
if letter2 > letter3:
middle = letter2
else:
middle = letter3
elif letter2 > letter3:
if letter3 > letter1:
middle = letter3
else:
middle = letter1
else:
if letter2 > letter1:
middle = letter2
else:
middle = letter1
print("The letter in the middle is " + middle)
# Tax Slabs - Gift Tax Calculator
#| Value of gift | Tax at the lower limit | Tax rate for the exceeding part (%) |
#| ------------------- | ---------------------- | ----------------------------------- |
#| 5 000 — 25 000 | 100 | 8 |
#| 25 000 — 55 000 | 1 700 | 10 |
#| 55 000 — 200 000 | 4 700 | 12 |
#| 200 000 — 1 000 000 | 22 100 | 15 |
#| 1 000 000 — | 142 100 | 17 |
gift = int(input("Value of gift: "))
if gift >= 1000000:
tax = 142100 + (gift - 1000000) * 0.17
elif gift >= 200000:
tax = 22100 + (gift - 200000) * 0.15
elif gift >= 55000:
tax = 4700 + (gift - 55000) * 0.12
elif gift >= 25000:
tax = 1700 + (gift - 25000) * 0.10
elif gift >= 5000:
tax = 100 + (gift - 5000) * 0.08
else:
tax = 0
if tax == 0:
print("No tax!")
else:
print(f"Amount of tax: {tax} euros")
# Implementation 2:
value = int(input("Value of gift: "))
if value < 5000:
tax = 0
elif value <= 25000:
tax = 100 + (value - 5000) * 0.08
elif value <= 55000:
tax = 1700 + (value - 25000) * 0.10
elif value <= 200000:
tax = 4700 + (value - 55000) * 0.12
elif value <= 1000000:
tax = 22100 + (value - 200000) * 0.15
else:
tax = 142100 + (value - 1000000) * 0.17
if tax == 0:
print("No tax!")
else:
print(f"Amount of tax: {tax} euros")