You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: programming/fzz-buzz-2-200-points.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ Oh no! Two of my keys are broken! Please help me make the same Fzz Buzz program,
4
4
5
5
As a side note, use of `eval()` and `exec()` is also frowned upon and will be marked invalid.
6
6
7
-
***This writeup is a python solution***
7
+
### Solution
8
8
9
-
### Summary
9
+
***This writeup is a python solution***
10
10
11
11
The goal of this challenge was to write a fizz buzz program without using the letter `i` or the question mark character `?`. You must read an integer `n` from stdin and print that many lines of fizz buzz. For example, if `n = 17`, output:
12
12
@@ -30,7 +30,7 @@ FizzBuzz
30
30
17
31
31
```
32
32
33
-
### How to get input / print
33
+
####How to get input / print
34
34
35
35
In order to get user input, you must call `input()` and likewise, to print you must call `print()`. Therefore, we need some way to alias these functions without using the character `i`.
36
36
@@ -52,7 +52,7 @@ p = getattr(globals()['__bu\x69lt\x69ns__'],'pr\x69nt')
52
52
53
53
Now `f` will call `input` and `p` will call `print`.
54
54
55
-
### How to loop
55
+
####How to loop
56
56
57
57
Since the user provides the number of lines to print, we must find some way to loop from `1` to `n`.
58
58
@@ -71,7 +71,7 @@ def go(k):
71
71
go(1) # Start the chain
72
72
```
73
73
74
-
### How to use conditionals?
74
+
####How to use conditionals?
75
75
76
76
We ran into a problem in our last task: we can't use `if` since it has an `i`. Therefore, we must find some other way to get conditional behavior.
77
77
@@ -94,7 +94,7 @@ a = ((k % 15 == 0) and p('F\x69zzBuzz'))
94
94
95
95
In the previous line, we first check if `k` (the line number) is divisible by `3` and `5` (or just `15`). If it is not, the conditional short-circuits and the right side is not evaluated. If it is, we call `p('F\x69zzBuzz')` which prints `FizzBuzz`. (The `a =` is just so that it is a valid expression).
96
96
97
-
### Putting it all together
97
+
####Putting it all together
98
98
99
99
Therefore, using all of these ideas, we can come up with the following program:
0 commit comments