Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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”
- newList = []
- #fizzbuzz = 15, 30, 45, 60, 75, 90
- for i in range(1,101):
- if i % 3 ==0 and i %5 ==0:
- i = 'FizzBuzz'
- elif i % 5 == 0:
- i = 'Buzz';
- elif i % 3 == 0:
- i = 'Fizz';
- newList.append(i)
- print(newList)
- #How many Fizz, how many Buzz, and how many Fizzbuzz in the list
- for a in newList:
- if a == 'FizzBuzz':
- print('The quantity of FizzBuzz is ' + str(newList.count(a)))
- break
- for b in newList:
- if b == 'Buzz':
- print('The quantity of Buzz is ' + str(newList.count(b)))
- break
- for c in newList:
- if c == 'Fizz':
- print('The quantity of Fizz is ' + str(newList.count(c)))
- break
- #Which elements in the list are not Fizz, Buzz, or FizzBuzz?
- x = newList
- y = []
- q1 = 'Fizz'
- q2= 'Buzz'
- q3 = 'FizzBuzz'
- for d in x:
- if d != q1 and d != q2 and d != q3:
- y.append(d)
- print(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement