From: Paddy3118 Date: 2007-06-10T14:20:05+09:00 Subject: Re: FizzBuzz (#126) On Jun 10, 6:14 am, Paddy3118 wrote: > On Jun 3, 5:43 pm, darren kirby wrote: > > > > > > > On with the code: > > > # fizz.rb > > 1.upto(ARGV[0].to_i) do |n| > > if n % 15 == 0 > > print "FizzBuzz " > > elsif n % 5 == 0 > > print "Buzz " > > elsif n % 3 == 0 > > print "Fizz " > > else print "#{n} " > > end > > end > > puts > > > # fizz.py > > import sys > > for n in range(1,int(sys.argv[1])+1): > > if n % 15 == 0: > > sys.stdout.write("FizzBuzz ") > > elif n % 3 == 0: > > sys.stdout.write("Fizz ") > > elif n % 5 == 0: > > sys.stdout.write("Buzz ") > > else: sys.stdout.write("%i " % n) > > print > > A slight clean-up of thePythoncode. > The trailing comma on the print will > add a space as separator. > > # fizz.py using print > import sys > for n in range(1, int(sys.argv[1])+1): > if n % 15 == 0: > print "FizzBuzz", > if n % 3 == 0: > print "Fizz", > if n % 5 == 0: > print "Buzz", > else: > print n, > print > > - Paddy. I'm a Dork! I posted my scriblings instead of: # fizz.py using print import sys for n in range(1, int(sys.argv[1])+1): if n % 15 == 0: print "FizzBuzz" elif n % 3 == 0: print "Fizz" elif n % 5 == 0: print "Buzz" else: print n print