elz (
elz) wrote in
intro_to_cs2009-11-11 10:52 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
Entry tags:
Poll & solutions
First:
Also, it occurs to me that it might be handy to have a place to post/discuss solutions to the problem sets, to see what we can learn from each other in the absence of TAs. If you actually go to MIT and the problem sets are still the same, don't read these. ;)
Fire away!
Open to: Registered Users, detailed results viewable to: All, participants: 25
Tickyboxes!
Also, it occurs to me that it might be handy to have a place to post/discuss solutions to the problem sets, to see what we can learn from each other in the absence of TAs. If you actually go to MIT and the problem sets are still the same, don't read these. ;)
Fire away!
no subject
#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