filmov
tv
GCSE Python Challenge #3: FizzBuzz

Показать описание
Practicing using lists and both FOR and WHILE looping in Python with a classic program assignment.
The challenge:
Create a program which replicates the famous game FizzBuzz. It works by counting up normally from 1, but:
-Any multiple of 3 is replaced by the word ‘Fizz’
-Any multiple of 5 is replaced by the word ‘Buzz’
-Any multiple of both 3 and 5 is replaced by the word ‘FizzBuzz!’
Your program should begin with the user being asked for how many FizzBuzzes they want printed.
The FizzBuzz sequence should then be generated and stored in a list. E.g. if the user wants 4 FizzBuzzes, then the list should be 60 items long.
Then, output the sequence in the list on the same line except when FizzBuzz is printed, like below:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14
FizzBuzz!
16, 17, Fizz, [etc....]
Success criteria:
Using user input
Use of iteration
Use of selection
Use of a list method
Use of the modulo operator
Use of a Boolean/logical operator
Comment(s) which explain any complex logic
Printing the contents of the list in the format specified
Extensions:
Validate the user input to ensure a suitable number is provided
Store the values in a 2D list so that the ‘original’ numbers are stored alongside their labels e.g. [[1,1],[2,2],[3,"Fizz"],[4,4],[5,"Buzz"].....]
My solution:
The challenge:
Create a program which replicates the famous game FizzBuzz. It works by counting up normally from 1, but:
-Any multiple of 3 is replaced by the word ‘Fizz’
-Any multiple of 5 is replaced by the word ‘Buzz’
-Any multiple of both 3 and 5 is replaced by the word ‘FizzBuzz!’
Your program should begin with the user being asked for how many FizzBuzzes they want printed.
The FizzBuzz sequence should then be generated and stored in a list. E.g. if the user wants 4 FizzBuzzes, then the list should be 60 items long.
Then, output the sequence in the list on the same line except when FizzBuzz is printed, like below:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14
FizzBuzz!
16, 17, Fizz, [etc....]
Success criteria:
Using user input
Use of iteration
Use of selection
Use of a list method
Use of the modulo operator
Use of a Boolean/logical operator
Comment(s) which explain any complex logic
Printing the contents of the list in the format specified
Extensions:
Validate the user input to ensure a suitable number is provided
Store the values in a 2D list so that the ‘original’ numbers are stored alongside their labels e.g. [[1,1],[2,2],[3,"Fizz"],[4,4],[5,"Buzz"].....]
My solution: