3 ms·
You can drop the extra () which brings it down to 80. for i in range(1,101):print("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else'')or i
by c4p 14y ago
You can drop the extra () which brings it down to 80.
for i in range(1,101):print("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else'')or i
- GregBuchholz 14y ago74 for i in range(1,101):print(''if i%3 else'Fizz')+(''if i%5 else'Buzz')or i
- y2bd 14y ago70 now, still same idea. for x in range(1,101):print['','Fizz'][x%3==0]+['','Buzz'][x%5==0]or x
- GregBuchholz 14y agoExcellent. Down to 68. for x in range(1,101):print['','Fizz'][x%3<1]+['','Buzz'][x%5<1]or x
- twiceaday 14y agoMy shortest Python solution is 59 characters. Two tricks, use while instead of range, and use string repetition instead of lists n=1 while n<101:print'Fizz'*(n%3<1)+'Buzz'*(n%5<1)or n;n+=1 And here is a wacky one in 96 chars w=range(101) w[::3]=['Fizz']*34 w[::5]=['Buzz']*21 w[::15]=['FizzBuzz']*7 for s in w[1:]:print s
- ajennings 14y agoYou can save one more character with an exec loop n=1;exec"print'Fizz'*(n%3<1)+'Buzz'*(n%5<1)or n;n+=1;"*100