Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python] Guess a number (1-100)
02-03-2010, 03:26 AM (This post was last modified: 03-21-2010 08:07 PM by Alphablend.)
Post: #1
[Python] Guess a number (1-100)
Believe it or not we had this task on Colloqia exam for Introduction to Computers. I did it in like... 3 min or something.
Lol funny thing was that about 50% of students did this one wrong. Lol
Code:
from random import randint
secret_number=randint(1,100)
number_attempts=0
while True:
    attempt=int(raw_input("Guess a number from range 1 - 100: "))
    if attempt==secret_number:
        print "Bravo! That was the secret number."
        print "You succeded from %d . try."% number_attempts
        break
    elif attempt<secret_number:
        print "Try a higher number."
        number_attempts+=1
    elif attempt>secret_number:
        print "Try a lower number."
        number_attempts+=1
Find all posts by this user
Quote this message in a reply
02-03-2010, 04:51 AM
Post: #2
RE: [Python] Guess a number (1-100)
Very good, fast and structured. Good piece of code !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
02-03-2010, 10:11 AM
Post: #3
RE: [Python] Guess a number (1-100)
I would of loved to had a college course in python. I have taken all the programming courses under my degree. I need to change my major to software engineer so I can take so more programming courses.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: