+ 1
FizzBuzz is a well known programming assignment, asked during interviews. The given code solves the FizzBuzz problem and uses
FizzBuzz is a well known programming assignment, asked during interviews. 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.
7 Antworten
+ 5
n = int(input())
for x in range(1, n , 2):
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)
+ 2
Ameen
Here is the code. Follow it and enjoy your learning
n = int(input())
for x in range( n):
if x%3 == 0 and x%5 == 0 and x%2 != 0:
print ("SoloLearn")
elif x%3 == 0 and x%5 == 0 and x%2 == 0:
continue
elif x%3 == 0 and x%2 == 0:
continue
elif x%3 == 0:
print("Solo")
elif x%5 == 0 and x%2 == 0:
continue
elif x%5 == 0:
print("Learn")
elif x%2 == 0:
continue
else:
print("x")
I hope u helpful it.
0
n=int(input())
for i in range(1,n+1,2):
if(i%15==0):
print("SoloLearn")
elif(i%5==0):
print("Learn")
elif(i%3==0):
print("Solo")
else:
print(i)
0
Great work Adi Nath Bhawani
0
Ameen
Can't help you without seeing your try.
Post it here or edit it in the question (and alert us).
https://www.sololearn.com/discuss/1316935/?ref=app
- 1
Here the code
n = int(input())
for x in range(1, n, 2):
if x % 3 == 0 and x % 5 == 0:
print("SoloLearn")
continue
elif x % 3 == 0:
print("Solo")
continue
elif x % 5 == 0:
print("Learn")
continue
else:
print(x)