Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67405 > unrolled thread

Re: Help with "Guess the number" script

Started byScott W Dunning <swdunning@cox.net>
First post2014-03-01 18:06 -0700
Last post2014-03-01 18:06 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-01 18:06 -0700

#67405 — Re: Help with "Guess the number" script

FromScott W Dunning <swdunning@cox.net>
Date2014-03-01 18:06 -0700
SubjectRe: Help with "Guess the number" script
Message-ID<mailman.7558.1393727434.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On Mar 1, 2014, at 9:35 AM, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> 	Without loops, one part of your assignment is going to be tedious,
> unless the intent is to only allow for one guess per run.
No, 10 guesses per game.  Yes very tedious and repetative.
> 
>> from random import randrange
>> randrange(1, 101)
> 
> 	You generated a random number and then threw it away.
>> 
>> from random import seed
>> seed(129)
I do not know what seed is.  The directions in the begining said to do that I guess to test the code through out writing it?  This is what the directions for that part said.
At the top of your file, import the randrange function from the random module. In order to test this module I also want you to import the seed function from the random module. Immediately after importing it I want you to call the seed function with an argument of 129. By calling the seed function we ensure that the sequence of random numbers you generate will exactly match the ones used in this document. 

> 
> 	Now you are seeding the random number generator but never generate a
> new number after it.
> 
>> 
>> def print_description():
>>   print """Welcome to Guess the Number.
>>   I have seleted a secret number in the range 1 ... 100.
>>   You must guess the number within 10 tries.
>>   I will tell you if you ar high or low, and
>>   I will tell you if you are hot or cold.\n"""
>> 
>> def get_guess(guess_number):
>>   print "(",guess_number,")""Plese enter a guess:"
>>   current_guess = raw_input()
>>   return int(guess_number)
> 
> 	You're returning the counter of how many guesses have been made, and
> dropping the player's guess into the trash
I actually do not understand what you mean here.  Should I get rid of the current_guess line completely?  Should it look more like this;

def get_guess(guess_number):
	raw_input(“Please enter a guess”)
	guess_number = int(guess_number)
	return (guess_number)
get_guess(1)
> 
>> 
>> def main():
>>   print_description()
>>   secret = 50
> 
> 	That's supposed to be the random number, isn't it?
Yes it is, I put 50 there because I was going to try and test it.  I think it should be secret = randrange(1,101) right?
> 
>>   current_guess = 1
>>   get_guess(1)
> 
> 	You drop the return value into the trash
> 
>>   if current_guess != secret():
> 
> 	You are /calling/ a function called secret -- which doesn't exist,
> since you bound it to the integer value 50; And current_guess doesn't exist
> in this function either.
> 
>>       print "Congratulations you win!!"
> 
> 
> 	Read the documentation on how function calls and return values operate.
> Hint: you need to do something with the returned value /at the point where
> you call the function/.
Hmm, ok I’ll try and find what I’m missing.

> 
> 	And -- as has been mentioned; these mistakes are better served in the
> tutor list, as they would be mistakes in /any/ common programming language.
> -- 
> 	
Yes, I’m sorry I completely forgot.  I’ll repost there and go that route.  Thanks though!


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web