zulu: Omar Epps, looking awesome (house - epps)
zulu ([personal profile] zulu) wrote in [community profile] intro_to_cs 2009-11-16 04:26 am (UTC)

On the other hand, check this out:

#odds

# This script will calculate the nth odd number

odd = 0
counter = 0
odds = []

print ("Let's find the nth odd number. Please enter a postive integer: ")
answer = raw_input()
nth = int(answer)

while counter < nth:
     if odd % 2 == 0:
          print str(odd) + (" is even. It doesn't go on the list.")
          odd = odd + 1
          print ("We have found ") + str(counter) +(" odd numbers. Let's keep going.")

     elif odd % 2 != 0:
          print str(odd) + " is odd. It goes on the list."
          odds.append(odd)
          if len(odds) == int(nth):
               print ("The ") + str(nth) + ("th odd number is ") + str(odd)
               break
          else:
               print ("We have found ") + str(len(odds)) +(" odd numbers. Let's keep going.")
               odd = odd + 1
               counter = counter + 1

Post a comment in response:

This community only allows commenting by members. You may comment here if you're a member of intro_to_cs.
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting