#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0

    Can someone check this for me?


    I'd like to add in come additional comments:

    The You're HOT and You're Freezing aren't working I'd like them when I get closer to the number like less than 5 numbers away I get the You're HOT instead of Warm and if I'm more than 30 away I'd like a Freezing statement...right now I can only get the You're HOT to come up when I guess the right number.

    Thanks in advance!
    Munk

    Code:

    import random # handy random-number functions

    def run():
    # pick a number in the range 1-100
    mynum = random.choice( range(100) ) + 1

    yourguess = 200 # what user guessed
    lastdist = 0 # last distance to mynum
    tries = 0 # number of tries so far

    print "I'm thinking of a number from 1 to 100."

    # main loop: repeat until user gets it right
    while yourguess != mynum:

    tries = tries + 1
    yourguess = input("Your guess? ")

    if (yourguess != mynum):

    # find how far off you are
    newdist = abs(yourguess - mynum)

    # print warmer/colder than last time

    if (lastdist == 0):
    print "Guess again..."
    elif (newdist > lastdist):
    print "You're getting colder."
    else:
    print "You're getting warmer."
    lastdist = newdist

    # print Hot/Freezing than last time

    if (newdist < 5 ):
    print "You're HOT"
    if (newdist > 30 ):
    print "You're Freezing"
    lastdist = newdist

    # end of the if statement
    # repeat until user gets it right

    print "Good job! That took", tries, "tries."

    # immediate-mode commands, for drag-and-drop or execfile() execution
    if __name__ == '__main__':
    run()
    print
    raw_input("press Return>")
    else:
    print "Module warmer imported."
    print "To run, type: warmer.run()"
    print "To reload after changes to the source, type: reload(warmer)"

    # end of warmer.py
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0
    Sorry...how do I get the code to hold it's structure in the post?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    9
    Rep Power
    0
    Code:
    import random		# handy random-number functions
    
    def run():
    	# pick a number in the range 1-100
    	mynum = random.choice( range(100) ) + 1
    	
    	yourguess = 200		# what user guessed
    	lastdist = 0		# last distance to mynum
    	tries = 0			# number of tries so far
    
    	print "I'm thinking of a number from 1 to 100."
    	
    	# main loop: repeat until user gets it right
    	while yourguess != mynum:
    	
    		tries = tries + 1
    		yourguess = input("Your guess? ")
    	
    		if (yourguess != mynum):
    		
    			# find how far off you are
    			newdist = abs(yourguess - mynum)
    	
    			# print warmer/colder than last time
    			
    			if (lastdist == 0):
    				print "Guess again..."
    			elif (newdist > lastdist):
    				print "You're getting colder."
    			else:
    				print "You're getting warmer."
    			lastdist = newdist
    			
    		# print Hot/Freezing than last time
    
            if (newdist < 5 ):
                print "You're HOT"
            if (newdist > 30 ):
                print "You're Freezing"
            lastdist = newdist
                
    # end of the if statement
    # repeat until user gets it right
    	
    	print "Good job!  That took", tries, "tries."
    
    # immediate-mode commands, for drag-and-drop or execfile() execution
    if __name__ == '__main__':
    	run()
    	print
    	raw_input("press Return>")
    else:
    	print "Module warmer imported."
    	print "To run, type: warmer.run()"
    	print "To reload after changes to the source, type: reload(warmer)"
    
    # end of warmer.py
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10
    first of all the way you are using random its not the best option, you should instead use mynum = random.randrange(100)+1

    second of all if the condition of the main loop is != mynum, you dont need to use an "if" with the same condition you just put everythiing that should happen if != mynum in the main level inside the loop.

    i dont totally understand what are you trying to do with newdist, lastdist, etc, because for example the user can input -100 so it will show it warmer because is smaller than the last time but maybe its worst than the last i think you should re-analize your methods there.

    byebye
    good luck

IMN logo majestic logo threadwatch logo seochat tools logo