0

Why is my answer wrong?

I'm trying to solve this assignment called FizzBuzz. This is the requirments: 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. It says my answers are wrong and I dont understand how. Please help https://code.sololearn.com/ceNv01Qyfgn6/?ref=app

1st Dec 2020, 3:37 AM
Dustin James Locey
Dustin James Locey - avatar
9 Antworten
+ 6
To skip even numbers, you need to code it out. The multiples of 3, multiples of 5, and multiples of 3 and 5 has been coded already. Even number means multiples of 2. I'm not sure if this applies but the API is: range(start, stop, step) start defaults to 0 (inclusive) stop is compulsory (exclusive) step defaults to 1 You might want to change line 3: "range(1, n)" to "range(1, n+1)". So that your input value is included. You can also set the step=2 as mentioned by Sanjyot21 to increment by 2 to skip even numbers.
1st Dec 2020, 3:54 AM
Lam Wei Li
Lam Wei Li - avatar
+ 5
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) Got it figured out. Thank you guys
1st Dec 2020, 4:12 AM
Dustin James Locey
Dustin James Locey - avatar
+ 4
Your code is the very same template code provided by SoloLearn. Your own answer is missing. "You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range." Just review the Control Structures module. You'll find a way there. It's hard to give hints without telling you the solution.
1st Dec 2020, 3:57 AM
Kevin ★
+ 3
Dustin James Locey You can also try to use range function as range(1,n,2) so that it will skip even numbers in loop
1st Dec 2020, 4:19 AM
Sanjyot21
Sanjyot21 - avatar
+ 1
I forgot about that one. Thank you Sanjyot21
1st Dec 2020, 4:21 AM
Dustin James Locey
Dustin James Locey - avatar
+ 1
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 % 7 == 0: print("Solo") elif x % 5 == 0: print("solo") else: print(learn) Help me please
29th Jan 2021, 10:53 AM
Arazil Parilla
Arazil Parilla - avatar
0
The input the question uses is 15 btw
1st Dec 2020, 3:45 AM
Dustin James Locey
Dustin James Locey - avatar
- 1
n = int(input()) for x in range(1, n): if not 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)
30th Apr 2021, 9:07 AM
Darshan S
- 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)
20th Jan 2022, 4:31 PM
Ahmed Madeh
Ahmed Madeh - avatar