Paddy
6/10/2007 5:17:00 AM
On Jun 10, 6:14 am, Paddy3118 <paddy3...@googlemail.com> wrote:
> On Jun 3, 5:43 pm, darren kirby <bulli...@badcomputer.org> 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