Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If I'm teaching young'ns per se using a toy language, I'd reach for Scratch. It's history and Google's embrace of it seem like strong endorsements. Are there other good candidates in that space?

If I'm teaching an intro class using a general purpose language, it's Ruby or Python. My heart lies with Ruby, but having basic Python chops is such a bigger win downstream.

  for i in range(1, 101):
      if i % 15:
          print ('FizzBuzz')
      elif i % 3 == 0:
          print ('Fizz')
      elif i % 5 == 0:
          print ('Buzz')
      else:
          print (str(i))

  (1..100).each do |i|
    if i % 15 == 0
      puts 'FizzBuzz'
    elsif i % 3 == 0
      puts 'Fizz'
    elsif i % 5 == 0
      puts 'Buzz'
    else
      puts i
    end
  end


  (1..100).each do |i|
   puts case
     when i % 15 == 0
       'FizzBuzz'
     when i % 3 == 0
       'Fizz'
     when i % 5 == 0
       'Buzz'
     else
       i
     end
   end


Yes, cleaner, and no switch in Python.


(offtopic) You might be missing an '== 0' in the second line there? I've never done fizzbuzz so I honestly don't know, but the ruby version has it.


Zero and empty lists and dictionaries are treated as False in Python.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: