Advertisement
asgfgh

Fizz Buzz

Jun 14th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. #Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”
  2.  
  3. newList = []
  4.  
  5. #fizzbuzz = 15, 30, 45, 60, 75, 90
  6. for i in range(1,101):
  7.   if i % 3 ==0 and i %5 ==0:
  8.     i = 'FizzBuzz'
  9.   elif i % 5 == 0:
  10.     i = 'Buzz';
  11.   elif i % 3 == 0:
  12.     i = 'Fizz';
  13.   newList.append(i)
  14. print(newList)
  15.  
  16. #How many Fizz, how many Buzz, and how many Fizzbuzz in the list
  17. for a in newList:
  18.   if a == 'FizzBuzz':
  19.     print('The quantity of FizzBuzz is ' + str(newList.count(a)))
  20.     break
  21.  
  22. for b in newList:
  23.   if b == 'Buzz':
  24.     print('The quantity of Buzz is ' + str(newList.count(b)))
  25.     break
  26.  
  27. for c in newList:
  28.   if c == 'Fizz':
  29.     print('The quantity of Fizz is ' + str(newList.count(c)))
  30.     break
  31.  
  32. #Which elements in the list are not Fizz, Buzz, or FizzBuzz?
  33. x = newList
  34. y = []
  35. q1 = 'Fizz'
  36. q2= 'Buzz'
  37. q3 = 'FizzBuzz'
  38. for d in x:
  39.   if d != q1 and d != q2 and d != q3:
  40.     y.append(d)
  41. print(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement