-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDay-13.py
More file actions
111 lines (90 loc) · 2.8 KB
/
Copy pathDay-13.py
File metadata and controls
111 lines (90 loc) · 2.8 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
## Day 13 - Section 13: Beginner - Debugging: How to Find and Fix Errors in your Code
''' Suggested steps:
- Describe the problem in your head - Untangle the problem
- Reproduce the bug
- Fix errors in IDE befre you continue
- Squash bugs with a print() statement
- Use a debugger
- Take a break and come back
- Ask for an external perspective
- Run your code often - after every little code execution
- Ask stackoverflow
'''
'''Instructions
Read this the code in main.py
Spot the problems 🐞.
Modify the code to fix the program.
Fix the code so that it works and passes the tests when you submit.
number = int(input()) # Which number do you want to check?
if number % 2 = 0:
print("This is an even number.")
else:
print("This is an odd number.")
'''
number = int(input()) # Which number do you want to check?
if number % 2 == 0: # learnt about = vs ==
print("This is an even number.")
else:
print("This is an odd number.")
'''Instructions
Read this the code in main.py
Spot the problems 🐞.
Modify the code to fix the program.
No shortcuts - don't copy-paste to replace the code entirely with a working solution.
Fix the code so that it works and when you hit submit it should pass all the tests.
# Which year do you want to check?
year = input()
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.")
'''
# Which year do you want to check?
year = int(input()) # Learnt about type errors
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.")
'''Instructions
Read this the code in main.py
Spot the problems 🐞.
Modify the code to fix the program.
No shortcuts - don't copy-paste to replace the code entirely with a working solution.
The code needs to print the solution to the FizzBuzz game.
Your program should print each number from 1 to x where x is the input number.
However when the number is divisible by 3 then instead of printing the number it should print "Fizz".
When the number is divisible by 5, then instead of printing the number it should print "Buzz".
And if the number is divisible by both 3 and 5 e.g. 15 then instead of the number it should print "FizzBuzz".
target = int(input())
for number in range(1, target + 1):
if number % 3 == 0 or number % 5 == 0:
print("FizzBuzz")
if number % 3 == 0:
print("Fizz")
if number % 5 == 0:
print("Buzz")
else:
print([number])
'''
target = int(input())
for number in range(1, target + 1):
if number % 3 == 0 and number % 5 == 0:
print("FizzBuzz")
elif number % 3 == 0:
print("Fizz")
elif number % 5 == 0:
print("Buzz")
else:
print(number)