- 1
How can I solve FizzBuzz problem?
I don't understand how will I solve this?
8 Answers
+ 3
the last section says you need to skip even numbers.
add another if statement.
if x % 2 == 0: # how to test for an even number
...
...
+ 2
as Slick suggested, I will only add
if x % 2 == 0:
continue # to pass even nums
# try to put this condition in the correct place
+ 1
Hi! Please, show us your attempt. You have a code?
0
Post your code so we can help. If you haven't written any yet, i suggest you go back over the previous lesson
0
n = int(input())
for x in range(1, n):
if x % 3 == 0 and x % 5 == 0:
print("SoloLearn")
elif x % 3 == 0:
print("Solo")
elif x % 5 == 0:
print("Learn")
else:
print(x)
# I can't solve it yet.
#The question is:
The given code solves the FizzBuzz problem and uses the words "Solo" and "Learn" instead of "Fizz" and "Buzz".
It takes an input n and outputs the numbers from 1 to n.
For each multiple of 3, print "Solo" instead of the number.
For each multiple of 5, prints "Learn" instead of the number.
For numbers which are multiples of both 3 and 5, output "SoloLearn".
You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range.
# so help me there.
0
Agregar en el primer elif lo siguiente:
elfi x % 2 == 0:
print("")
no hay necesidad de imprimir el nĂșmero, solo que sea la primera iteraciĂłn y que omita el nĂșmero par.
- 1
You need to follow the suggestions already given to you...twice.
In the correct place add:
elif x % 2 == 0:
continue