Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sheila Hunter
188 PointsHow to get a if statement to look at two variables at once
So I'm running the code
is_Fizz= number%3 is_Buzz= number%5
print("Hello", name) print("So you picked",number,"lets see if thats a Buzz or Fizz or both!")
if is_Buzz and is_Fizz ==0: print("thats a buzzfizz!")
elif is_Fizz <= 0: print("thats a fizz!")
elif is_Buzz <= 0: print("thats a buzz!")
else: print("thats not bizzy or fuzzy!")
and for some reason whenever I feed this the any number divisible by 3 it gives me a buzzfizz and if I give it the number 15 it would give me a buzz. I don't understand what is going wrong here.
1 Answer
Scott Bailey
13,190 Pointsif is_Buzz == 0 and is_Fizz == 0:
print("thats a buzzfizz!")
This would let you compare if both are True, you were close.
Another way that would work is:
if not is_Buzz and not is_Fizz:
print("thats a buzzfizz!")
0 = Falsey 1 = Truthy As the return on 15 % 5 = 0 and 15 % 3 = 0 both are read as False on the statement. So the last example is saying if both are not False (ie True) then it will print.
I'm not sure which is better or even if one is better but both will work!
Full code:
name = input("Enter Name: ")
number = input("Enter Number: ")
is_Fizz = (int(number) % 3)
is_Buzz = (int(number) % 5)
print(f"Hello {name}")
print(f"So you picked {number} lets see if thats a Buzz or Fizz or both!")
if is_Buzz == 0 and is_Fizz == 0:
print("thats a buzzfizz!")
elif is_Fizz <= 0:
print("thats a fizz!")
elif is_Buzz <= 0:
print("thats a buzz!")
else:
print("thats not bizzy or fuzzy!")