Ludootje
03-10-2002, 04:52 PM
Some of you might remember me asking helping about this on LNO, well, I still haven't fixed it :(
I mailed the guy who wrote the tutorial from which I learned some python, and the guy didn't found it neither, I hope you people can help.
# the point is to create a simple random number generator, and let the user guess the number
print " Guess the number game"
print " -------------------"
print ""
player1 = raw_input("What's your name?" )
# problem 1: have to put space between the question mark & the input by the user, how do I do this?
print ""
play = 1
while play == 1:
print "Now, the program will generate a number."
print "To do this, please enter one or more random numbers",player1,"."
print ""
randomnumber = int(input("Random numbers?" ))
# problem 2: have to put space between question mark & the input by the user
number = randomnumber
except ValueError:
print "That wasn't a number."
print "Please enter numbers",player1,"."
# currently, the number to guess is still identical to the "random numbers" given by the user,
# to test the program and to be sure it works like it should
# though, I have no idea how to let it generate a randomnumber.
# probably something like "import randomnumber" in the beginning, anyone knows this?
wrongnumber = 1
while wrongnumber == 1:
guess = int(input("Type in a number:" ))
except ValueError:
print "That wasn't a number."
print "Please type a number",player1,"."
# problem 3: have to put space between question mark & the input by the user
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
# here starts the "real" problem:
# I think it's something with the while
# at the end of gtn.py explanations are given about the problem
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
if guess >= number:
print "The number is lower, guess again."
elif guess <= number:
print "The number is higher, guess again."
else:
print "You won, it was", number,"."
wrongnumber = 0
play = 0
rs = raw_input("Would you like to replay (r) or quit (q)? ")
if rs != q:
play = 1
# headproblem: no matter if the quess is higher, lower or equal to the number, the output will be "The number is lower, guess again."
# NOTE: no error is given by python
I've put gtn.txt (it seems .py-files aren't accepted?) as an attachment too, so it would be easier to d/l it for you.
I mailed the guy who wrote the tutorial from which I learned some python, and the guy didn't found it neither, I hope you people can help.
# the point is to create a simple random number generator, and let the user guess the number
print " Guess the number game"
print " -------------------"
print ""
player1 = raw_input("What's your name?" )
# problem 1: have to put space between the question mark & the input by the user, how do I do this?
print ""
play = 1
while play == 1:
print "Now, the program will generate a number."
print "To do this, please enter one or more random numbers",player1,"."
print ""
randomnumber = int(input("Random numbers?" ))
# problem 2: have to put space between question mark & the input by the user
number = randomnumber
except ValueError:
print "That wasn't a number."
print "Please enter numbers",player1,"."
# currently, the number to guess is still identical to the "random numbers" given by the user,
# to test the program and to be sure it works like it should
# though, I have no idea how to let it generate a randomnumber.
# probably something like "import randomnumber" in the beginning, anyone knows this?
wrongnumber = 1
while wrongnumber == 1:
guess = int(input("Type in a number:" ))
except ValueError:
print "That wasn't a number."
print "Please type a number",player1,"."
# problem 3: have to put space between question mark & the input by the user
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
# here starts the "real" problem:
# I think it's something with the while
# at the end of gtn.py explanations are given about the problem
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
if guess >= number:
print "The number is lower, guess again."
elif guess <= number:
print "The number is higher, guess again."
else:
print "You won, it was", number,"."
wrongnumber = 0
play = 0
rs = raw_input("Would you like to replay (r) or quit (q)? ")
if rs != q:
play = 1
# headproblem: no matter if the quess is higher, lower or equal to the number, the output will be "The number is lower, guess again."
# NOTE: no error is given by python
I've put gtn.txt (it seems .py-files aren't accepted?) as an attachment too, so it would be easier to d/l it for you.