+ 6

FizzBuzz problem is a well known programming assignment, asked during interviews.

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. 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) Help me to solve this problem

13th Oct 2020, 4:49 AM
Karan
Karan - avatar
51 Réponses
+ 47
#Here's 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)
18th Oct 2020, 7:13 AM
Muhammad Rukban Ali Yousaf
Muhammad Rukban Ali Yousaf - avatar
+ 12
Solution 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)
13th Oct 2020, 5:13 AM
Karan
Karan - avatar
+ 7
The range begins with 1, to ensure that only odd numbers are processed, you can use the range stepping of 2 for x in range(1, n, 2): # codes here And cache the modulo results so your code doesn't have to do it multiple times.
13th Oct 2020, 5:11 AM
Ipang
+ 7
Solution would be n = int(input()) for x in range(1, n): if x %2 !=0: 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) else: continue
22nd Jan 2021, 6:21 AM
Ruzan Bhadha
Ruzan Bhadha - avatar
+ 4
Solution Rmbr to add the 3rd argument in the range to give it a sequence in this case our third argument will be 2 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)
3rd Feb 2021, 5:11 AM
Ronny Karani
Ronny Karani - avatar
+ 3
Use this code ....proof 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)
4th Jul 2021, 6:04 AM
Tanay Patil
Tanay Patil - avatar
+ 2
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)
22nd Apr 2021, 2:23 PM
Prateek Gupta
Prateek Gupta - avatar
+ 2
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) #if you like this program upvote me
7th May 2021, 6:00 PM
LAKSHMI NARAYANAN M
LAKSHMI NARAYANAN M - avatar
+ 2
n = int(input()) for x in range(1, n): if x % 2 == 0: continue elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
13th Aug 2021, 10:28 AM
Shree Harini
Shree Harini - avatar
+ 2
You just have to write a line of code to skip the even numbers, but that line must come first in the code block, because there are even numbers that are multiple of 3 an 2 at the same time (ex: 6), and even numbers that are multiple of 3 and 5 (ex: 60): n = int(input()) for x in range(1, n): if x % 2 == 0: #to skip the even numbers continue elif x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
30th May 2022, 4:28 PM
Carlos Sekine
Carlos Sekine - avatar
+ 1
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)
16th Jan 2021, 3:50 PM
Saurabh Kumar Thakur
Saurabh Kumar Thakur - avatar
+ 1
Try this x = int(input()) for i in range(1, x,2): if i % 3 == 0 and i % 5 == 0: print("SoloLearn") elif i% 3 == 0: print("Solo") elif i % 5 == 0: print("Learn") else: print(i)
30th Mar 2021, 9:07 PM
Kabelo Michael Letlala
Kabelo Michael Letlala - avatar
+ 1
This is mine. 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") elif x % 2 > 0: print(x) continue
15th Apr 2021, 2:58 PM
Rithish
+ 1
# it is answer from Aman Saini , I hope this answer is useful for you 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)
25th Apr 2021, 11:33 AM
Aman saini
Aman saini - avatar
+ 1
#Solution would be n = int(input()) for x in range(1, n): if not x %2==0: 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)
19th Jul 2021, 11:16 PM
Peyman Daei Rezaei
Peyman Daei Rezaei - avatar
+ 1
n = int(input()) for x in range(1, n): if not x % 2 == 0: 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)
31st Jul 2021, 4:35 AM
Devendra Sahu
Devendra Sahu - avatar
+ 1
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) just add continue
3rd Oct 2021, 8:25 AM
HARSHIL RAMANI
HARSHIL RAMANI - avatar
+ 1
n = int(input()) for i in range(n): if i%2==0: i+=1 elif i%3==0 and i%5==0: print("SoloLearn") continue elif i%5==0: print("Learn") continue elif i%3==0: print("Solo") continue else: print(i)
17th Dec 2021, 4:03 PM
A.N.Harish Ram
A.N.Harish Ram - avatar
+ 1
Check this out; n = int(input()) for x in range(1, n): if x % 2 == 0: continue 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)
27th Jan 2023, 6:13 AM
Himasha Nethmini
Himasha Nethmini - avatar
+ 1
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 elif x%2 == 0: break else: print(x)
16th Apr 2023, 2:47 AM
AMINE MOUTAOUAKKIL