- 3
How can I solve 30 code project in python.
9 Réponses
0
You have to change you code to skip all the even numbers(2,4,,8, 3579182). All even numbers are divisible by 2. So, you have to skip all the numbers that is divisible by 2.
Hint: use "if" with "continue" statement.
+ 3
one by one
0
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)
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")
elif x%2==0:
continue
Check this...Scarlet Witch
0
I solved it like this and it seemed too easy! I'm no coder, so is it really this easy?!
n = int(input())
for x in range(1, n, 2): #added a 2 here
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)
0