9 Replies - 695 Views - Last Post: 17 October 2013 - 05:35 PM Rate Topic: -----

#1 Profound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-October 13

Help with a number guessing game

Posted 15 October 2013 - 03:20 PM

Well hello there, I have been asked to make a simple number guessing game in python however I'm completely lost.
I have to use a import random number function, the number has to be in between 1-1000
As for example, if a computer was to generate a number such as 569 and my first guess would be 165, number 6 will come up as "Y" and other numbers as "N". I also only have 10 tries to get the number, please keep it as simple as possible and do use loop function if possible, thanks a lot.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with a number guessing game

#2 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 32
  • View blog
  • Posts: 254
  • Joined: 11-May 13

Re: Help with a number guessing game

Posted 15 October 2013 - 05:14 PM

Please, read the rules before you post this is violation of the Rule of 'Gimme Teh Codez'. We don't like to just give code out here.

What we do like to do is help you, make your own code, and in the long run, become a better programmer/developer in the end!

This post will more than likely be locked by a moderator, feel free to post again, but this time, don't just ask for code!
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7875
  • View blog
  • Posts: 13,365
  • Joined: 19-March 11

Re: Help with a number guessing game

Posted 15 October 2013 - 05:24 PM

DblAAssassin is correct, this thread will be locked unless I see some signs of self-directed effort.
Examples of self-directed effort would include some code and specific questions about it, or specific questions about the design of such a program, or something of that nature: basically, we want to answer questions, we don't want to do your homework for you.


The assumption I start out with is that you have been given an assignment by someone who thinks you should be able to do this work, and that doing this work will help you learn something about programming in python. I'm not going to question that person's judgement. Show us what you've got.
Was This Post Helpful? 0
  • +
  • -

#4 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 32
  • View blog
  • Posts: 254
  • Joined: 11-May 13

Re: Help with a number guessing game

Posted 15 October 2013 - 05:40 PM

The best way to tackle a programming project or any project for that matter is to break it down piece by piece.

View PostProfound, on 15 October 2013 - 03:20 PM, said:

I have to use a import random number function, the number has to be in between 1-1000
As for example, if a computer was to generate a number such as 569 and my first guess would be 165, number 6 will come up as "Y" and other numbers as "N". I also only have 10 tries to get the number.


Just, read this excerpt, and I expect if you have been taught proficiently, that you can turn this simple text to extravagant python!
Was This Post Helpful? 1
  • +
  • -

#5 Profound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-October 13

Re: Help with a number guessing game

Posted 16 October 2013 - 02:58 AM

Hi, I'm so sorry i didn't mean to offend you in any way. And yes of course I have tried to make some code but it didn't work as expected....
import random
number = random.randint(1,9999)
answer = input("Please enter a number: ")
if number ("")
input ("Y")
else ("N")
break
print("You have entered correct number")

Don't get me wrong, I know c++ and html but I'm totally knew to python and even though people say it's easy I seem to be having difficulties with it....
Was This Post Helpful? 0
  • +
  • -

#6 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 32
  • View blog
  • Posts: 254
  • Joined: 11-May 13

Re: Help with a number guessing game

Posted 16 October 2013 - 05:23 PM

A couple of things...

1. In the random.randint parentheses, this is where you put the range. In our case 1-1,000. There fore you would need to put random.randint(1,1000).

2. The best way to do this project would be to use a while loop, and have it run, for a max of 10 times, or till the user, guesses the number. You will want an else if the loop have to break due to the user not guessing correctly in the 10 turns he/she has. Also, you will want this line in the loop...
answer = input("Please enter a number: ")


What a while loop looks like...
while count < 5: #Don't forget the colon.
    count += 1  #Make sure there is whitespace (press tab or space 4 times)
    print("word") 



3. When making your if statement, think about what you are comparing the random generated number and the user's input or answer right? Yes, 'lookie' there you have conveniently stored these to things into variable named number & answer! So as long as the number and answer are not equal, and the counter is not more than 10, you want the loop to stop running! An if statement looks like...
if tiger != cow:
    print("Taxonomy")



Hope this helped! Give it another go, this time using the advice I have provided!
If you still need more help check out these links and/or post here again!

http://docs.python.o...ontrolflow.html (Has a lot of other stuff, mainly focus on first part 'if statement')

http://docs.python.o...while-statement (Again focus on 'if & while statements')
Was This Post Helpful? 0
  • +
  • -

#7 Profound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-October 13

Re: Help with a number guessing game

Posted 17 October 2013 - 02:59 AM

Hello and thank you very much for a reply, however I'm confused at step 3, I got it to repeat 10 times and even to tell you if your guess is too low or too high however I'm unable to do the following: if a computer generates number 555 and my guess would be 657 it will just say my guess is too high, instead I would like it to say NYN as in i guessed the middle number right and others not, thank you
Was This Post Helpful? 0
  • +
  • -

#8 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 32
  • View blog
  • Posts: 254
  • Joined: 11-May 13

Re: Help with a number guessing game

Posted 17 October 2013 - 05:25 AM

Are, you want to get into that? It involves delving into the world of lists!
Yes, you would use if statements to see if the list(number), and the answer match. The reason, I'm making sure is 'cause list can be quite a difficult topic for new python programmers. I think your professor should be the one to teach you, as I might confuse you.
Was This Post Helpful? 0
  • +
  • -

#9 Profound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-October 13

Re: Help with a number guessing game

Posted 17 October 2013 - 07:46 AM

View PostDblAAssassin, on 17 October 2013 - 05:25 AM, said:

Are, you want to get into that? It involves delving into the world of lists!
Yes, you would use if statements to see if the list(number), and the answer match. The reason, I'm making sure is 'cause list can be quite a difficult topic for new python programmers. I think your professor should be the one to teach you, as I might confuse you.


Please do try, basically what I have to do is make a computer generate a number (Which I did with the random feature). Then when i guess the number if at least one of them is right it will say "Y" otherwise all the others would say "N". Thank you
Was This Post Helpful? 0
  • +
  • -

#10 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 32
  • View blog
  • Posts: 254
  • Joined: 11-May 13

Re: Help with a number guessing game

Posted 17 October 2013 - 05:35 PM

Do and read through these and you should have a pretty good understanding of list.

  • Lists (Codecademy) Only the first two sections are over list.
  • I suggest you watch thenewboston's videos on this, just look up on YouTube 'thenewboston lists python'


If you need any help post here! Good Luck!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1