-
Notifications
You must be signed in to change notification settings - Fork 0
/
day13.py
88 lines (69 loc) · 2.03 KB
/
day13.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
# Day 13: Debugging
############DEBUGGING#####################
# # Describe Problem
def my_function():
for i in range(1, 20): # range does not include upper limit
if i == 20:
print("You got it")
my_function()
# # Reproduce the Bug
from random import randint
dice_imgs = ["❶", "❷", "❸", "❹", "❺", "❻"]
dice_num = randint(1, 6) # index starts at 0 and should end at 5
print(dice_imgs[dice_num]) # sometimes gives error
# # Play Computer
year = int(input("What's your year of birth? "))
if year > 1980 and year < 1994:
print("You are a millenial.")
elif year > 1994: # no output for 1994
print("You are a Gen Z.")
# # Fix the Errors
age = input("How old are you?") # needs to be an integer: int()
if age > 18:
print(f"You can drive at age {age}.") # needs to be indented
# #Print is Your Friend
pages = 0
word_per_page = 0
pages = int(input("Number of pages: "))
word_per_page == int(input("Number of words per page: ")) # needs to be a single =
total_words = pages * word_per_page
print(total_words)
# #Use a Debugger
def mutate(a_list):
b_list = []
for item in a_list:
new_item = item * 2
b_list.append(new_item) # needs to be indented to run for every element in list
print(b_list)
mutate([1,2,3,5,8,13])
###############
# Exercise 1
number = int(input("Which number do you want to check?"))
if number % 2 == 0: # needed to be double = for conditions
print("This is an even number.")
else:
print("This is an odd number.")
###############
# Exercise 2
year = int(input("Which year do you want to check?")) # needed to be an integer
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Leap year.")
else:
print("Not leap year.")
else:
print("Leap year.")
else:
print("Not leap year.")
##################
# Exercise
for number in range(1, 101):
if number % 3 == 0 and number % 5 == 0: # and not or
print("FizzBuzz")
elif number % 3 == 0: # elif not if
print("Fizz")
elif number % 5 == 0: # elif not if
print("Buzz")
else:
print([number])