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


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

Help with guessing game :D

Started byRobert Gonda <robertgonda1994@gmail.com>
First post2013-10-29 04:45 -0700
Last post2013-10-30 01:30 +0000
Articles 20 on this page of 37 — 8 participants

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


Contents

  Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 04:45 -0700
    Re: Help with guessing game :D Chris Angelico <rosuav@gmail.com> - 2013-10-29 22:53 +1100
      Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 04:54 -0700
        Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 05:05 -0700
          Re: Help with guessing game :D Alister <alister.ware@ntlworld.com> - 2013-10-29 12:58 +0000
            Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 06:03 -0700
              Re: Help with guessing game :D Alister <alister.ware@ntlworld.com> - 2013-10-29 13:07 +0000
                Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 06:10 -0700
                  Re: Help with guessing game :D Alister <alister.ware@ntlworld.com> - 2013-10-29 14:25 +0000
                    Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 07:40 -0700
                      Re: Help with guessing game :D Alister <alister.ware@ntlworld.com> - 2013-10-29 16:19 +0000
                        Re: Help with guessing game :D Neil Cerutti <neilc@norwich.edu> - 2013-10-29 17:22 +0000
                          Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 10:32 -0700
                      Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 09:24 -0700
                        Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 09:31 -0700
                          Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 09:40 -0700
                            Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 10:05 -0700
                              Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 10:13 -0700
                    Re: Help with guessing game :D rurpy@yahoo.com - 2013-10-29 10:24 -0700
                      Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 10:45 -0700
                        Re: Help with guessing game :D rurpy@yahoo.com - 2013-10-29 11:27 -0700
                          Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 11:35 -0700
                            Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 12:03 -0700
                              Re: Help with guessing game :D rurpy@yahoo.com - 2013-10-29 12:55 -0700
                                Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 13:08 -0700
                                Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 13:21 -0700
                                  Re: Help with guessing game :D rurpy@yahoo.com - 2013-10-29 14:25 -0700
                      Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 10:52 -0700
                        Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 10:55 -0700
                        Re: Help with guessing game :D rurpy@yahoo.com - 2013-10-29 11:26 -0700
                          Re: Help with guessing game :D rusi <rustompmody@gmail.com> - 2013-10-29 11:32 -0700
    Re: Help with guessing game :D Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-29 13:44 +0000
      Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 06:52 -0700
    Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 11:05 -0700
      Re: Help with guessing game :D Dave Angel <davea@davea.name> - 2013-10-29 19:09 +0000
        Re: Help with guessing game :D Robert Gonda <robertgonda1994@gmail.com> - 2013-10-29 12:15 -0700
          Re: Help with guessing game :D Dave Angel <davea@davea.name> - 2013-10-30 01:30 +0000

Page 1 of 2  [1] 2  Next page →


#57904 — Help with guessing game :D

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 04:45 -0700
SubjectHelp with guessing game :D
Message-ID<37245746-51cc-4040-9493-1921369023fb@googlegroups.com>
Hey guys, so I figured I will give python a shot. I got to exercise that has asked me to create a number guessing game which weren't a problem, 
guessesTaken = 0 #This is a "Guesses taken counter"
print("Hello, what's your name?") #Asking the user to input their name
N = raw_input() #What the user's name is
import random #This is importing the random function
number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000
print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
while guessesTaken < 10: 
    print('Take a guess.') 
    guess = input()
    guess = int(guess)
    guessesTaken = guessesTaken + 1
    if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
        print('Your guess is too low.') 
    if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
        print('Your guess is too high.')
    if guess == number:
        break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results
if guess == number:
    guessesTaken = str(guessesTaken)
    print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
    number = str(number)
    print("No, the right number was" + number)

However the problem is that it also asked me to do the following : If at least one of the digit guessed is right it will say "y" otherwise "n" which I can't seem to do :/ any help?

[toc] | [next] | [standalone]


#57905

FromChris Angelico <rosuav@gmail.com>
Date2013-10-29 22:53 +1100
Message-ID<mailman.1756.1383047638.18130.python-list@python.org>
In reply to#57904
On Tue, Oct 29, 2013 at 10:45 PM, Robert Gonda
<robertgonda1994@gmail.com> wrote:
> N = raw_input() #What the user's name is
> print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
>     guess = input()
>     guess = int(guess)

Which version of Python are you using? The raw_input call is very
Python 2, but you're using print as a function, and then you're
converting input()'s result to an integer, both of which suggest
Python 3.x. If you're using Python 2, do NOT use input() - it is
dangerous, deceptively so. In Python 3, that problem no longer
applies.

ChrisA

[toc] | [prev] | [next] | [standalone]


#57906

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 04:54 -0700
Message-ID<f6521641-6e2a-4194-8b29-8a69bce04aac@googlegroups.com>
In reply to#57905
On Tuesday, 29 October 2013 11:53:55 UTC, Chris Angelico  wrote:
> On Tue, Oct 29, 2013 at 10:45 PM, Robert Gonda
> 
> <robertgonda1994@gmail.com> wrote:
> 
> > N = raw_input() #What the user's name is
> 
> > print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
> 
> >     guess = input()
> 
> >     guess = int(guess)
> 
> 
> 
> Which version of Python are you using? The raw_input call is very
> 
> Python 2, but you're using print as a function, and then you're
> 
> converting input()'s result to an integer, both of which suggest
> 
> Python 3.x. If you're using Python 2, do NOT use input() - it is
> 
> dangerous, deceptively so. In Python 3, that problem no longer
> 
> applies.
> 
> 
> 
> ChrisA

Hi Chris and thanks for the reply, I'm using python 3.

[toc] | [prev] | [next] | [standalone]


#57907

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 05:05 -0700
Message-ID<717fb444-1ffc-4f92-a929-c2a9069bce19@googlegroups.com>
In reply to#57906
On Tuesday, 29 October 2013 11:54:49 UTC, Robert Gonda  wrote:
> On Tuesday, 29 October 2013 11:53:55 UTC, Chris Angelico  wrote:
> 
> > On Tue, Oct 29, 2013 at 10:45 PM, Robert Gonda
> 
> > 
> 
> > <robertgonda1994@gmail.com> wrote:
> 
> > 
> 
> > > N = raw_input() #What the user's name is
> 
> > 
> 
> > > print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
> 
> > 
> 
> > >     guess = input()
> 
> > 
> 
> > >     guess = int(guess)
> 
> > 
> 
> > 
> 
> > 
> 
> > Which version of Python are you using? The raw_input call is very
> 
> > 
> 
> > Python 2, but you're using print as a function, and then you're
> 
> > 
> 
> > converting input()'s result to an integer, both of which suggest
> 
> > 
> 
> > Python 3.x. If you're using Python 2, do NOT use input() - it is
> 
> > 
> 
> > dangerous, deceptively so. In Python 3, that problem no longer
> 
> > 
> 
> > applies.
> 
> > 
> 
> > 
> 
> > 
> 
> > ChrisA
> 
> 
> 
> Hi Chris and thanks for the reply, I'm using python 3.

Tried to get rid of it but it just gives me an error, that's why I used raw_input

[toc] | [prev] | [next] | [standalone]


#57910

FromAlister <alister.ware@ntlworld.com>
Date2013-10-29 12:58 +0000
Message-ID<BhObu.26730$eW3.25642@fx14.am4>
In reply to#57907
On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
>> 
>> > 
>> > converting input()'s result to an integer, both of which suggest
>> 
>> 

if you need to be checking individual digits you are probably best 
keeping the input & number to be checked as strings.

it would then be a trivial task to expand this program to work with words 
as well as numbers.




-- 
"No one gets too old to learn a new way of being stupid."

[toc] | [prev] | [next] | [standalone]


#57911

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 06:03 -0700
Message-ID<3ab8c365-0985-4035-947c-4d991d9690d7@googlegroups.com>
In reply to#57910
On Tuesday, 29 October 2013 12:58:09 UTC, Alister  wrote:
> On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
> 
> >> 
> 
> >> > 
> 
> >> > converting input()'s result to an integer, both of which suggest
> 
> >> 
> 
> >> 
> 
> 
> 
> if you need to be checking individual digits you are probably best 
> 
> keeping the input & number to be checked as strings.
> 
> 
> 
> it would then be a trivial task to expand this program to work with words 
> 
> as well as numbers.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> "No one gets too old to learn a new way of being stupid."

I see, so how should i do it? I wouldn't mind having no text in it I just need the program to generate the number and the user to try to guess what the number is, so for example if a python would generate num 770 and the user would guess 870 it would say NYN

[toc] | [prev] | [next] | [standalone]


#57912

FromAlister <alister.ware@ntlworld.com>
Date2013-10-29 13:07 +0000
Message-ID<0qObu.26731$eW3.17586@fx14.am4>
In reply to#57911
On Tue, 29 Oct 2013 06:03:55 -0700, Robert Gonda wrote:

> On Tuesday, 29 October 2013 12:58:09 UTC, Alister  wrote:
>> On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
>> 
>> 
>> >> 
>> 
>> >> > 
>> >> > converting input()'s result to an integer, both of which suggest
>> 
>> 
>> >> 
>> 
>> >> 
>> 
>> 
>> if you need to be checking individual digits you are probably best
>> 
>> keeping the input & number to be checked as strings.
>> 
>> 
>> 
>> it would then be a trivial task to expand this program to work with
>> words
>> 
>> as well as numbers.
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> --
>> 
>> "No one gets too old to learn a new way of being stupid."
> 
> I see, so how should i do it? I wouldn't mind having no text in it I
> just need the program to generate the number and the user to try to
> guess what the number is, so for example if a python would generate num
> 770 and the user would guess 870 it would say NYN

remember that strings are a sequence.
they can be used as iterators & sliced in the same way as lists & tuples.




-- 
Let a fool hold his tongue and he will pass for a sage.
		-- Publilius Syrus

[toc] | [prev] | [next] | [standalone]


#57913

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 06:10 -0700
Message-ID<a307611a-c9f7-4c41-856f-564ab7dbb089@googlegroups.com>
In reply to#57912
On Tuesday, 29 October 2013 13:07:08 UTC, Alister  wrote:
> On Tue, 29 Oct 2013 06:03:55 -0700, Robert Gonda wrote:
> 
> 
> 
> > On Tuesday, 29 October 2013 12:58:09 UTC, Alister  wrote:
> 
> >> On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> > 
> 
> >> >> > converting input()'s result to an integer, both of which suggest
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> 
> 
> >> if you need to be checking individual digits you are probably best
> 
> >> 
> 
> >> keeping the input & number to be checked as strings.
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> it would then be a trivial task to expand this program to work with
> 
> >> words
> 
> >> 
> 
> >> as well as numbers.
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> --
> 
> >> 
> 
> >> "No one gets too old to learn a new way of being stupid."
> 
> > 
> 
> > I see, so how should i do it? I wouldn't mind having no text in it I
> 
> > just need the program to generate the number and the user to try to
> 
> > guess what the number is, so for example if a python would generate num
> 
> > 770 and the user would guess 870 it would say NYN
> 
> 
> 
> remember that strings are a sequence.
> 
> they can be used as iterators & sliced in the same way as lists & tuples.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Let a fool hold his tongue and he will pass for a sage.
> 
> 		-- Publilius Syrus

Now you have confused me completely, sorry im just new to python and just learning everything :) could you perhaps give me an example? or part of the code that's missing?

[toc] | [prev] | [next] | [standalone]


#57919

FromAlister <alister.ware@ntlworld.com>
Date2013-10-29 14:25 +0000
Message-ID<azPbu.26732$eW3.9171@fx14.am4>
In reply to#57913
On Tue, 29 Oct 2013 06:10:30 -0700, Robert Gonda wrote:

> On Tuesday, 29 October 2013 13:07:08 UTC, Alister  wrote:
>> On Tue, 29 Oct 2013 06:03:55 -0700, Robert Gonda wrote:
>> 
>> 
>> 
>> > On Tuesday, 29 October 2013 12:58:09 UTC, Alister  wrote:
>> 
>> >> On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
>> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> >> 
>> 
>> >> 
>> 
>> >> >> > 
>> >> >> > converting input()'s result to an integer, both of which
>> >> >> > suggest
>> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> >> 
>> 
>> >> 
>> 
>> >> >> 
>> 
>> >> 
>> 
>> >> 
>> >> if you need to be checking individual digits you are probably best
>> 
>> 
>> >> 
>> >> keeping the input & number to be checked as strings.
>> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> >> it would then be a trivial task to expand this program to work with
>> 
>> >> words
>> 
>> 
>> >> 
>> >> as well as numbers.
>> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> 
>> >> 
>> >> --
>> 
>> 
>> >> 
>> >> "No one gets too old to learn a new way of being stupid."
>> 
>> 
>> > 
>> > I see, so how should i do it? I wouldn't mind having no text in it I
>> 
>> > just need the program to generate the number and the user to try to
>> 
>> > guess what the number is, so for example if a python would generate
>> > num
>> 
>> > 770 and the user would guess 870 it would say NYN
>> 
>> 
>> 
>> remember that strings are a sequence.
>> 
>> they can be used as iterators & sliced in the same way as lists &
>> tuples.
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> --
>> 
>> Let a fool hold his tongue and he will pass for a sage.
>> 
>> 		-- Publilius Syrus
> 
> Now you have confused me completely, sorry im just new to python and
> just learning everything :) could you perhaps give me an example? or
> part of the code that's missing?

you will probably learn more through trial & error than you will from 
being given an answer

to shine some more light on my advise try the following

code="7689"
for digit in code:
	print(digit)

does this give you any Ideas on how to proceed?



-- 
If you're right 90% of the time, why quibble about the remaining 3%?

[toc] | [prev] | [next] | [standalone]


#57922

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 07:40 -0700
Message-ID<99ff184c-8e49-48d5-97f8-1a7be0a57ca0@googlegroups.com>
In reply to#57919
On Tuesday, 29 October 2013 14:25:10 UTC, Alister  wrote:
> On Tue, 29 Oct 2013 06:10:30 -0700, Robert Gonda wrote:
> 
> 
> 
> > On Tuesday, 29 October 2013 13:07:08 UTC, Alister  wrote:
> 
> >> On Tue, 29 Oct 2013 06:03:55 -0700, Robert Gonda wrote:
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> > On Tuesday, 29 October 2013 12:58:09 UTC, Alister  wrote:
> 
> >> 
> 
> >> >> On Tue, 29 Oct 2013 05:05:19 -0700, Robert Gonda wrote:
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> >> > 
> 
> >> >> >> > converting input()'s result to an integer, both of which
> 
> >> >> >> > suggest
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> if you need to be checking individual digits you are probably best
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> keeping the input & number to be checked as strings.
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> it would then be a trivial task to expand this program to work with
> 
> >> 
> 
> >> >> words
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> as well as numbers.
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> --
> 
> >> 
> 
> >> 
> 
> >> >> 
> 
> >> >> "No one gets too old to learn a new way of being stupid."
> 
> >> 
> 
> >> 
> 
> >> > 
> 
> >> > I see, so how should i do it? I wouldn't mind having no text in it I
> 
> >> 
> 
> >> > just need the program to generate the number and the user to try to
> 
> >> 
> 
> >> > guess what the number is, so for example if a python would generate
> 
> >> > num
> 
> >> 
> 
> >> > 770 and the user would guess 870 it would say NYN
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> remember that strings are a sequence.
> 
> >> 
> 
> >> they can be used as iterators & sliced in the same way as lists &
> 
> >> tuples.
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> --
> 
> >> 
> 
> >> Let a fool hold his tongue and he will pass for a sage.
> 
> >> 
> 
> >> 		-- Publilius Syrus
> 
> > 
> 
> > Now you have confused me completely, sorry im just new to python and
> 
> > just learning everything :) could you perhaps give me an example? or
> 
> > part of the code that's missing?
> 
> 
> 
> you will probably learn more through trial & error than you will from 
> 
> being given an answer
> 
> 
> 
> to shine some more light on my advise try the following
> 
> 
> 
> code="7689"
> 
> for digit in code:
> 
> 	print(digit)
> 
> 
> 
> does this give you any Ideas on how to proceed?
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> If you're right 90% of the time, why quibble about the remaining 3%?

Unfortunately I'm not that sort of person, the way my brain learns is by experimenting, but first I need to know exactly what to write. Then I will play around with it and customize it to my needs, sorry to be such a bother guys :/ and thanks again for your help it's appreciated a lot :)

[toc] | [prev] | [next] | [standalone]


#57928

FromAlister <alister.ware@ntlworld.com>
Date2013-10-29 16:19 +0000
Message-ID<neRbu.26733$eW3.19770@fx14.am4>
In reply to#57922
On Tue, 29 Oct 2013 07:40:20 -0700, Robert Gonda wrote:
>> >> 
>> >> remember that strings are a sequence.
>> >> they can be used as iterators & sliced in the same way as lists &
>> 
>> >> tuples.
>> >> 
>> >> Let a fool hold his tongue and he will pass for a sage.
>> 
>> 
>> >> 
>> >> 		-- Publilius Syrus
>> 
>> 
>> > 
>> > Now you have confused me completely, sorry im just new to python and
>> > just learning everything :) could you perhaps give me an example? or
>> > part of the code that's missing?

>> you will probably learn more through trial & error than you will from
>> being given an answer
>> 
>> to shine some more light on my advise try the following
>> 
>> code="7689"
>> for digit in code:
>> 	print(digit)
>> 
>> does this give you any Ideas on how to proceed?
> 
> Unfortunately I'm not that sort of person, the way my brain learns is by
> experimenting, but first I need to know exactly what to write. Then I
> will play around with it and customize it to my needs, sorry to be such
> a bother guys :/ and thanks again for your help it's appreciated a lot
> :)

I wont provide the code but i will try to break the problem down into 
simple steps (this is the most important skill to develop in programming)


set the number to be guessed
get the user input
step through each digit in the input
compare to the co-responding digit in the number to be guessed
generate the required output

actually let me just expand on my earlier teaser code

does this switch on any light-bulbs for you

data='7865'
guess=input('guess')
for key,digit in enumerate(data):
	print digit,guess[key]
-- 
Watch all-night Donna Reed reruns until your mind resembles oatmeal.

[toc] | [prev] | [next] | [standalone]


#57937

FromNeil Cerutti <neilc@norwich.edu>
Date2013-10-29 17:22 +0000
Message-ID<bda95sFgst9U1@mid.individual.net>
In reply to#57928
On 2013-10-29, Alister <alister.ware@ntlworld.com> wrote:
> set the number to be guessed
> get the user input
> step through each digit in the input
> compare to the co-responding digit in the number to be guessed
> generate the required output
>
> actually let me just expand on my earlier teaser code
>
> does this switch on any light-bulbs for you
>
> data='7865'
> guess=input('guess')
> for key,digit in enumerate(data):
> 	print digit,guess[key]

I just want to add that this programming exercise, while pretty
common, stinks.

A new programmer shouldn't be embroiled in the morass of
interactive programming.

-- 
Neil Cerutti

[toc] | [prev] | [next] | [standalone]


#57939

Fromrusi <rustompmody@gmail.com>
Date2013-10-29 10:32 -0700
Message-ID<51cb6d33-76b8-415b-bef3-27baa2c15463@googlegroups.com>
In reply to#57937
On Tuesday, October 29, 2013 10:52:04 PM UTC+5:30, Neil Cerutti wrote:
> I just want to add that this programming exercise, while pretty
> common, stinks.
> 
> A new programmer shouldn't be embroiled in the morass of
> interactive programming.

Cheers to that!
If the 'print' statement were called a 'debug' statement, then it would be more clear that a clean and correct program should have no debug (ie print) statements.

[toc] | [prev] | [next] | [standalone]


#57929

Fromrusi <rustompmody@gmail.com>
Date2013-10-29 09:24 -0700
Message-ID<923e6cd4-350b-49df-ba38-c812650d481b@googlegroups.com>
In reply to#57922
On Tuesday, October 29, 2013 8:10:20 PM UTC+5:30, Robert Gonda wrote:
 
> Unfortunately I'm not that sort of person, the way my brain learns is by 
> experimenting, but first I need to know exactly what to write. Then I will play 
> around with it and customize it to my needs, sorry to be such a bother guys :/ 
> and thanks again for your help it's appreciated a lot :)

D
o
n
't

w
o
r
r
y

R
o
b
e
r
t

In case you did not get the gist of 
https://wiki.python.org/moin/GoogleGroupsPython
(which is a it verbose)
your posts come to us like the above.
Just keep a line of context and trim off the rest
a
n
d

y
o
u

s
h
o
u
l
d

b
e

f
i
n
e

[toc] | [prev] | [next] | [standalone]


#57931

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 09:31 -0700
Message-ID<fd2ca25d-8659-44c5-8f9f-577d48adefe4@googlegroups.com>
In reply to#57929
On Tuesday, 29 October 2013 16:24:57 UTC, rusi  wrote:
> On Tuesday, October 29, 2013 8:10:20 PM UTC+5:30, Robert Gonda wrote:
> 
>  
> 
> > Unfortunately I'm not that sort of person, the way my brain learns is by 
> 
> > experimenting, but first I need to know exactly what to write. Then I will play 
> 
> > around with it and customize it to my needs, sorry to be such a bother guys :/ 
> 
> > and thanks again for your help it's appreciated a lot :)
> 
> 
> 
> D
> 
> o
> 
> n
> 
> 't
> 
> 
> 
> w
> 
> o
> 
> r
> 
> r
> 
> y
> 
> 
> 
> R
> 
> o
> 
> b
> 
> e
> 
> r
> 
> t
> 
> 
> 
> In case you did not get the gist of 
> 
> https://wiki.python.org/moin/GoogleGroupsPython
> 
> (which is a it verbose)
> 
> your posts come to us like the above.
> 
> Just keep a line of context and trim off the rest
> 
> a
> 
> n
> 
> d
> 
> 
> 
> y
> 
> o
> 
> u
> 
> 
> 
> s
> 
> h
> 
> o
> 
> u
> 
> l
> 
> d
> 
> 
> 
> b
> 
> e
> 
> 
> 
> f
> 
> i
> 
> n
> 
> e

> > I honestly don't get it? this any better? ;D

[toc] | [prev] | [next] | [standalone]


#57932

Fromrusi <rustompmody@gmail.com>
Date2013-10-29 09:40 -0700
Message-ID<d06d37d7-1d13-421a-abc4-8b5cd3fd0f4f@googlegroups.com>
In reply to#57931
On Tuesday, October 29, 2013 10:01:38 PM UTC+5:30, Robert Gonda wrote:

> > > I honestly don't get it? this any better? ;D

In google groups you will see a small 'show quoted text'
Click it you will see what a cascading avalanche of mess is produced.


Yes GG is stupid, not you. But if you use it (as many of us here do) you are expected to compensate for that stupidity

[toc] | [prev] | [next] | [standalone]


#57935

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 10:05 -0700
Message-ID<5a6f641c-00d7-41db-96e1-a912a73c8e5e@googlegroups.com>
In reply to#57932
On Tuesday, 29 October 2013 16:40:01 UTC, rusi  wrote:
> On Tuesday, October 29, 2013 10:01:38 PM UTC+5:30, Robert Gonda wrote:
> 
> 
> 
> > > > I honestly don't get it? this any better? ;D
> 
> 
> 
> In google groups you will see a small 'show quoted text'
> 
> Click it you will see what a cascading avalanche of mess is produced.
> 
> 
> 
> 
> 
> Yes GG is stupid, not you. But if you use it (as many of us here do) you are expected to compensate for that stupidity

> Is this better then?

[toc] | [prev] | [next] | [standalone]


#57936

Fromrusi <rustompmody@gmail.com>
Date2013-10-29 10:13 -0700
Message-ID<a96a8da2-c84d-4457-9708-01cb6d6e6121@googlegroups.com>
In reply to#57935
On Tuesday, October 29, 2013 10:35:52 PM UTC+5:30, Robert Gonda wrote:
> > Is this better then?

By a bit. For most here not enough
Open the 'show quoted text' in your last post it shows like so
[Ive replaced '>' by '&' so GG will show it

& On Tuesday, October 29, 2013 10:01:38 PM UTC+5:30, Robert Gonda wrote:
&  
&  
&  
& > > > I honestly don't get it? this any better? ;D
&  
&  
&  
& In google groups you will see a small 'show quoted text'
&  
& Click it you will see what a cascading avalanche of mess is produced.
&  
&  
&  
&  
&  
& Yes GG is stupid, not you. But if you use it (as many of us here do) you are expected to compensate for that stupidity 

Now the actual content and what people expect to see is the following


& On Tuesday, October 29, 2013 10:01:38 PM UTC+5:30, Robert Gonda wrote:
&  
& > > > I honestly don't get it? this any better? ;D
&  
& In google groups you will see a small 'show quoted text'
& Click it you will see what a cascading avalanche of mess is produced.
& Yes GG is stupid, not you. But if you use it (as many of us here do) you are expected to compensate for that stupidity 

[toc] | [prev] | [next] | [standalone]


#57938

Fromrurpy@yahoo.com
Date2013-10-29 10:24 -0700
Message-ID<326cd185-06ba-4c59-b495-c04a9b2dc43b@googlegroups.com>
In reply to#57919
On 10/29/2013 05:45 AM, Robert Gonda wrote:
> Hey guys, so I figured I will give python a shot. I got to exercise that has asked me to create a number guessing game which weren't a problem, 
> guessesTaken = 0 #This is a "Guesses taken counter"
> print("Hello, what's your name?") #Asking the user to input their name
> N = raw_input() #What the user's name is
> import random #This is importing the random function
> number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000
> print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
> while guessesTaken < 10: 
>     print('Take a guess.') 
>     guess = input()
>     guess = int(guess)
>     guessesTaken = guessesTaken + 1
>     if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
>         print('Your guess is too low.') 
>     if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
>         print('Your guess is too high.')
>     if guess == number:
>         break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results
> if guess == number:
>     guessesTaken = str(guessesTaken)
>     print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
> if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
>     number = str(number)
>     print("No, the right number was" + number)
> 
> However the problem is that it also asked me to do the following : If at least one of the digit guessed is right it will say "y" otherwise "n" which I can't seem to do :/ any help?

and

On 10/29/2013 08:25 AM, Alister wrote:
> On Tue, 29 Oct 2013 06:10:30 -0700, Robert Gonda wrote:
>[...]
>> Now you have confused me completely, sorry im just new to python and
>> just learning everything :) could you perhaps give me an example? or
>> part of the code that's missing?
> 
> you will probably learn more through trial & error than you will from 
> being given an answer

While this is true for some people sometimes, I don't think
it is always true.  Very often it is easier and faster to 
learn something be seeing a worked out example and studying
it to see how it works.  This is especially true when one 
is new to a programming language and doesn't have a good
understanding of the terminology and concepts that people
who have been using the language take for granted.

> to shine some more light on my advise try the following
> 
> code="7689"
> for digit in code:
> 	print(digit)
> 
> does this give you any Ideas on how to proceed?

Robert, please see if this is what you were trying to do:

-------------------------
guessesTaken = 0 #This is a "Guesses taken counter"
print("Hello, what's your name?") #Asking the user to input their name
N = input() #What the user's name is
import random #This is importing the random function
number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000

number_str = str (number)     # Convert 'guess' to a string of digits.
while len (number_str) < 3:   # If there are less than 3 digits, add leading "0"s until it is three digits.
    number_str = "0" + number_str

print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
while guessesTaken < 10: 
    print('Take a guess.') 
    guess = input()
    guess = int(guess)
    guessesTaken = guessesTaken + 1
    if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
        print('Your guess is too low.') 
    if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
        print('Your guess is too high.')
    if guess == number:
        break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results

    guess_str = str (guess)     # Convert 'guess' to a string of digits.
    while len (guess_str) < 3:  # If there are less than 3 digits, add leading "0"s until it is three digits.
        guess_str = "0" + guess_str
    if len (guess_str) > 3: guess_str = guess_str[-2:]  # Make sure it is no longer than 3 digits.
    # Here, we know that 'number_str' is exactly 3 digits.  'guess_str' is at least
    # 3 digits but could be more if the user entered, for example, 34567.
    print ("digits matched: ", end='')
    for i in range (2, -1, -1):
        # 'i' will have the values, 2, 1, 0. 
        if guess_str[i] == number_str[i]: print ("Y", end='')
        else: print ("N", end='')
    print()

if guess == number:
    guessesTaken = str(guessesTaken)
    print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
    number = str(number)
    print("No, the right number was" + number)
-------------------------

Some comments...
  guess_str[-2:]
you want to read about "slices" in the Python docs, for example
  http://docs.python.org/2/tutorial/introduction.html#strings
The -2 means indexing starts counting from the right end of the string 
rather than the left had the index been positive.

  print ("Y", end='')
The end='' means don't print a newline after printing the "Y" string.
See http://docs.python.org/2/library/functions.html#print

Also, what Mark and Rusi were trying to say (not very clearly)
is that when you post from Google Groups, Google Groups insert
a lot of empty lines in the ">" the at the top of the message.

Look at your message, 
  https://groups.google.com/d/msg/comp.lang.python/6WMfzbtIyi8/AV4sce1zPicJ
(make sure to click the "- show quoted text -" link!) 
to see what everybody who doesn't use Google Groups sees.

When post a message, please try to edit you message before
you send it to get rid of  those blank lines.  In most cases
you can get rid of all the ">" text, *except* for a small
amount that gives the gist of what you are responding to.

[toc] | [prev] | [next] | [standalone]


#57942

FromRobert Gonda <robertgonda1994@gmail.com>
Date2013-10-29 10:45 -0700
Message-ID<0a99d12f-e711-4a05-854d-19dfa65c1d8c@googlegroups.com>
In reply to#57938
On Tuesday, October 29, 2013 5:24:08 PM UTC, ru...@yahoo.com wrote:
> On 10/29/2013 05:45 AM, Robert Gonda wrote:
> 
> > Hey guys, so I figured I will give python a shot. I got to exercise that has asked me to create a number guessing game which weren't a problem, 
> 
> > guessesTaken = 0 #This is a "Guesses taken counter"
> 
> > print("Hello, what's your name?") #Asking the user to input their name
> 
> > N = raw_input() #What the user's name is
> 
> > import random #This is importing the random function
> 
> > number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000
> 
> > print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
> 
> > while guessesTaken < 10: 
> 
> >     print('Take a guess.') 
> 
> >     guess = input()
> 
> >     guess = int(guess)
> 
> >     guessesTaken = guessesTaken + 1
> 
> >     if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
> 
> >         print('Your guess is too low.') 
> 
> >     if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
> 
> >         print('Your guess is too high.')
> 
> >     if guess == number:
> 
> >         break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results
> 
> > if guess == number:
> 
> >     guessesTaken = str(guessesTaken)
> 
> >     print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
> 
> > if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
> 
> >     number = str(number)
> 
> >     print("No, the right number was" + number)
> 
> > 
> 
> > However the problem is that it also asked me to do the following : If at least one of the digit guessed is right it will say "y" otherwise "n" which I can't seem to do :/ any help?
> 
> 
> 
> and
> 
> 
> 
> On 10/29/2013 08:25 AM, Alister wrote:
> 
> > On Tue, 29 Oct 2013 06:10:30 -0700, Robert Gonda wrote:
> 
> >[...]
> 
> >> Now you have confused me completely, sorry im just new to python and
> 
> >> just learning everything :) could you perhaps give me an example? or
> 
> >> part of the code that's missing?
> 
> > 
> 
> > you will probably learn more through trial & error than you will from 
> 
> > being given an answer
> 
> 
> 
> While this is true for some people sometimes, I don't think
> 
> it is always true.  Very often it is easier and faster to 
> 
> learn something be seeing a worked out example and studying
> 
> it to see how it works.  This is especially true when one 
> 
> is new to a programming language and doesn't have a good
> 
> understanding of the terminology and concepts that people
> 
> who have been using the language take for granted.
> 
> 
> 
> > to shine some more light on my advise try the following
> 
> > 
> 
> > code="7689"
> 
> > for digit in code:
> 
> > 	print(digit)
> 
> > 
> 
> > does this give you any Ideas on how to proceed?
> 
> 
> 
> Robert, please see if this is what you were trying to do:
> 
> 
> 
> -------------------------
> 
> guessesTaken = 0 #This is a "Guesses taken counter"
> 
> print("Hello, what's your name?") #Asking the user to input their name
> 
> N = input() #What the user's name is
> 
> import random #This is importing the random function
> 
> number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000
> 
> 
> 
> number_str = str (number)     # Convert 'guess' to a string of digits.
> 
> while len (number_str) < 3:   # If there are less than 3 digits, add leading "0"s until it is three digits.
> 
>     number_str = "0" + number_str
> 
> 
> 
> print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
> 
> while guessesTaken < 10: 
> 
>     print('Take a guess.') 
> 
>     guess = input()
> 
>     guess = int(guess)
> 
>     guessesTaken = guessesTaken + 1
> 
>     if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
> 
>         print('Your guess is too low.') 
> 
>     if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
> 
>         print('Your guess is too high.')
> 
>     if guess == number:
> 
>         break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results
> 
> 
> 
>     guess_str = str (guess)     # Convert 'guess' to a string of digits.
> 
>     while len (guess_str) < 3:  # If there are less than 3 digits, add leading "0"s until it is three digits.
> 
>         guess_str = "0" + guess_str
> 
>     if len (guess_str) > 3: guess_str = guess_str[-2:]  # Make sure it is no longer than 3 digits.
> 
>     # Here, we know that 'number_str' is exactly 3 digits.  'guess_str' is at least
> 
>     # 3 digits but could be more if the user entered, for example, 34567.
> 
>     print ("digits matched: ", end='')
> 
>     for i in range (2, -1, -1):
> 
>         # 'i' will have the values, 2, 1, 0. 
> 
>         if guess_str[i] == number_str[i]: print ("Y", end='')
> 
>         else: print ("N", end='')
> 
>     print()
> 
> 
> 
> if guess == number:
> 
>     guessesTaken = str(guessesTaken)
> 
>     print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
> 
> if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
> 
>     number = str(number)
> 
>     print("No, the right number was" + number)
> 
> -------------------------
> 
> 
> 
> Some comments...
> 
>   guess_str[-2:]
> 
> you want to read about "slices" in the Python docs, for example
> 
>   http://docs.python.org/2/tutorial/introduction.html#strings
> 
> The -2 means indexing starts counting from the right end of the string 
> 
> rather than the left had the index been positive.
> 
> 
> 
>   print ("Y", end='')
> 
> The end='' means don't print a newline after printing the "Y" string.
> 
> See http://docs.python.org/2/library/functions.html#print
> 
> 
> 
> Also, what Mark and Rusi were trying to say (not very clearly)
> 
> is that when you post from Google Groups, Google Groups insert
> 
> a lot of empty lines in the ">" the at the top of the message.
> 
> 
> 
> Look at your message, 
> 
>   https://groups.google.com/d/msg/comp.lang.python/6WMfzbtIyi8/AV4sce1zPicJ
> 
> (make sure to click the "- show quoted text -" link!) 
> 
> to see what everybody who doesn't use Google Groups sees.
> 
> 
> 
> When post a message, please try to edit you message before
> 
> you send it to get rid of  those blank lines.  In most cases
> 
> you can get rid of all the ">" text, *except* for a small
> 
> amount that gives the gist of what you are responding to.

> >Thank you very much for your reply, however it gives me an error, something about the "end", do you know whats wrong with it? (Still not sure if im posting this right so sorry)

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

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


csiph-web