0
[SOLVED] About the FuzzBuzz project
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) The input is automatically 15, and the output is: 1 Solo Learn 7 SoloLearn 11 13 If 0 stands for False, why does it print "Solo", "Learn", and "SoloLearn"? Am I missing something very simple?
20 Antworten
+ 3
Abhay so it compares the remainder of x%3 with 0, the remainder of 15%3 (x%3) is 0 so 0 == 0 equals true. Thank youu very much, I followed you
+ 3
Great!
+ 3
#TRY THIS ONE
n = int(input())
for x in range(1, n):
if x % 2 ==0:
continue
if x % 15 ==0:
print ("SoloLearn")
if x % 3==0:
print ("Solo")
if x % 5==0:
print ("Learn")
else:
print (x)
AND LET ME KNOW WHAT'S YOUR ANS BEFORE PLZ
+ 2
Yes,15%3 means 15 divided 3 with remainder being 0 ,just to clear as I got confused why you used x%3 in bracket.
+ 2
Albanianz if you still have doubt related to the output you can ask me anytime!
+ 2
Thanks
+ 1
Abhay I still don't understand it, can you explain it simplier or with more details?
+ 1
Albanianz I can't explain in a more simple way than this.
Do you know what remainder means? suppose x is 3 , so 3%3 will result in 0 and expression ( 0==0 ) will result in True as "==" operator checks if value on both sides are equal.
+ 1
Yes I misunderstood something but it's clear now thanks
+ 1
Btw do you know the code line to make the program automatically chose a number between 1-1000? Its something with randint() but I haven't learned it yet and I want to make a number guessing game but I don't understand it
+ 1
Albanianz yes ,
import random
print(random.randint(1,1000))
+ 1
Msg me for any further queries on this program
+ 1
Thanks I had already solved the project but wondered why it was "0" and got the answer from Abhay
+ 1
https://www.sololearn.com/coach/612?ref=app this is the correct fizz buzz program u can try this Albanianz
0
Yes False do equates to 0 or vice-versa(maybe) but 0 here stands for an actual integer, if you divide a number say 3 by 3 , you get remainder as 0 .
So in this piece of code x%3 == 0 , where % operator returns remainder, if you have 3%3==0 , it will result in True.
0
n=int(input())
for i in range(1,n+1):
if i%5==0 and i%3==0:
print("Solo learn")
elif i%3==0 and i%5!=0:
print("solo")
elif i%5==0 and i%3!=0:
print("learn")
else:
print(i)
Use this one bro
0
Bro it's not getting crct output
0
x = int(input())
if x > 5:
if x < 8:
print(x+1)
else:
print(x-1)
else:
print(x)
A) 8
- 1
thnwjjwnnaiwjnwjwuahuajbsksnhsms