-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_structure_exercises.py
More file actions
240 lines (163 loc) · 3.47 KB
/
Copy pathcontrol_structure_exercises.py
File metadata and controls
240 lines (163 loc) · 3.47 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python
# coding: utf-8
# In[45]:
day_of_the_week = str(input())
if day_of_the_week == 'Monday':
print(f'Today is {day_of_the_week}.')
else:
print('Today is not Monday!')
# In[43]:
if day_of_the_week == 'Saturday' or day_of_the_week == 'Sunday':
print('It is the weekend.')
else:
print('Today is a weekday.')
# In[15]:
hours_worked = 45
hourly_rate = 30
paycheck = 0
overtime = 0
if hours_worked > 40:
overtime = hours_worked - 40
hours_worked -= overtime
paycheck = (hours_worked * hourly_rate) + (overtime * (hourly_rate * 1.5))
print(paycheck)
# In[18]:
i = 5
while i <= 15:
print(i)
i += 1
# In[19]:
i = 0
while i <= 100:
print(i)
i += 2
# In[20]:
i = 100
while i >= -10:
print(i)
i -= 5
# In[21]:
i = 2
while i <= 1000000:
print(i)
i **= 2
# In[23]:
i = 100
while i > 0:
print(i)
i -= 5
# In[40]:
i = int(input())
for n in range(1, 11):
print(i, 'x ', f'{n} =', i * n)
# In[39]:
for n in range(1, 10):
print(n*f'{n}')
# In[46]:
print('Input a positive integer:')
i = int(input())
while i >= 1:
print(i)
i -= 1
# In[49]:
print('Input a positive integer:')
i = int(input())
n = 0
while n <= i:
print(n)
n += 1
# In[60]:
print('Input an odd number between 1 and 50')
i = input()
if i.isdigit() != True:
print('Make sure you entered a valid input!:')
i = int(input())
else:
i = int(i)
for n in range (1, 50):
if n % 2 == 1:
if n == i:
print('Yikes! Skipping number:', i)
else:
print('Heres an odd number:', n)
# In[2]:
i = 1
while i <= 100:
if i % 3 == 0 and i % 5 == 0:
print('FizzBuzz')
elif i % 3 == 0:
print('Fizz')
elif i % 5 == 0:
print('Buzz')
else:
print(i)
i += 1
# In[37]:
while True:
i = int(input('What number would you like to go up to? '))
print('Here is your table!')
print('number | squared| cubed')
print('------ | -------| ------')
n = 1
while n <= i:
print(f'{n}\t|{n**2}\t|{n**3}')
n += 1
while True:
answer = str(input('Run again? (y/n): '))
if answer in ('y', 'n'):
break
print("invalid input.")
if answer == 'y':
continue
else:
print("Goodbye")
break
# In[34]:
while True:
print('Enter a numerical grade:')
i = int(input())
if 100 >= i >= 88:
print('A')
elif 87 >= i >= 80:
print('B')
elif 79 >= i >= 67:
print('C')
elif 66 >= i >= 60:
print('D')
elif i <= 59:
print('F')
while True:
answer = str(input('Run again? (y/n): '))
if answer in ('y', 'n'):
break
print("invalid input.")
if answer == 'y':
continue
else:
print("Goodbye")
break
# In[46]:
books = [{
'title': 'Harry Potter',
'author': 'J.K. Rowling',
'genre': 'fantasy',
},
{
'title': 'Percy Jackson',
'author': 'Rick Riordan',
'genre': 'greek mythology',
},
{
'title': 'Lord of the Rings',
'author': 'J.R.R. Tolkien',
'genre': 'fantasy'
},
{
'title': 'The Great Gatsby',
'author': 'F. Scott Fitzgerald',
'genre': 'fiction'
}]
requested_genre = input('What genre are you interested in? ')
requested_books = [n['title'] for n in books if n['genre'] == requested_genre]
print(requested_books)
# In[ ]: