[Tutor] Re: Why can't I make this function work? (original) (raw)

Matt Smith smith-matt at tiscali.co.uk
Fri Jul 16 17:32:54 CEST 2004


On Thu, 15 Jul 2004 20:35:56 +0100, Matt Smith wrote:

I have written the following function as part of my guessing game program (as discussed in another thread):

def Getint(): "Function to collect an integer from the user" typecheck = 0 while typecheck == 0: int = rawinput() if type(int) != type(1): print "Invalid input" else: typecheck = 1 return int

Thanks for the help, I've re-written the funcion as below and it seams to work correctly now.

def Get_int(): "Function to collect a integer from the user" type_check = 0 while type_check == 0: try: integer = int(raw_input()) type_check = 1 except: print "Invalid input, try agin. ", return integer

Cheers, Matt.



More information about the Tutor mailing list