Sep-20-2022, 03:53 AM
Hello,
Having an issue with the Fizz Buzz challenge using the While Loop. Any help would be greatly appreciated. Please note I HAVE TO USE the while loop. Any help would be much appreciated!
the 2 issues are:
1. I cannot get past the first conditional ( keeps printing "foobarbaz")
2. I cannot end the loop.
Having an issue with the Fizz Buzz challenge using the While Loop. Any help would be greatly appreciated. Please note I HAVE TO USE the while loop. Any help would be much appreciated!
the 2 issues are:
1. I cannot get past the first conditional ( keeps printing "foobarbaz")
2. I cannot end the loop.
MAXVAL = 30 while (i < MAXVAL+1): if i % 2 == 0 and i % 3 == 0 and i % 5 == 0: print ('foobarbaz') elif i % 2 == 0 and i % 3 == 0: print ('foobar') elif i % 3 == 0 and i % 5 == 0: print("barbaz") elif i % 2 == 0 and i % 5 == 0: print('foobaz') # If the number is divisible by 2, print the word bar elif i % 2 == 0: print('foo') # If the number is divisible by 3, print the word bar elif i % 3 == 0: print('bar') #If the number is divisible by 5, print the word baz elif i % 5 == 0: print('baz') #If the number is not divisible by 2,3 or 5, do not print a string elif i % 2 == 1 or i % 3 == 1 or i % 5 == 1: print ()