View Full Version: Guess the number game

C++ Learning Community > Other Programing Languages > Guess the number game


Title: Guess the number game
Description: I wrote it in python tonight... bored...


ih8censorship - February 18, 2006 12:24 AM (GMT)
i was a bit bored tonight, so i decided to learn a little python.So i made this guess the number game, you can set the maximum random number on it too using the commandline... anyway i suppose it never hurts to know a bit about other languages even if you have no clue what youd do with them :lol: the only thing i can say i really dont care for in python is the forced indents... sure it forces your code to be readable but its a pain in the butt when you have been indenting one way for so long and then get forced into annother way :rolleyes:
CODE
import random
import sys
def main(maxnum):
num2guess=random.randrange(maxnum)
numguessed=0
print int(sys.argv[1])

while numguessed != num2guess:
 numguessed=int(raw_input("Enter a number to guess: "))
 if numguessed == num2guess:
  print "you win!"
 elif numguessed > num2guess:
  print "Sorry, but the number is smaller."
 elif numguessed < num2guess:
  print "Sorry but the number is larger."
 

main(int(sys.argv[1]))




* Hosted for free by InvisionFree