October 15th, 2013, 05:48 PM

Help with simple program
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 an import random number function, the number has to be in between 11000
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". Keep it as simple as possible, thank you a lot. If possible do use a loop function, thanks again
This is what i got but of course it's completely wrong but you get the idea
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")
October 15th, 2013, 10:06 PM

Congratulations! You wrote a couple lines of code that might be useful in a working program.
Code:
import random # useful
number = random.randint(1,9999) # NO
answer = input("Please enter a number: ") # useful
if number ("") # NO
input ("Y") # NO
else ("N") # NO
break # has possibilities.
print("You have entered correct number") # not great, but OK.
For your effort I give you 30 lines randomly chosen from a large body of python modules I've written for myself and kept.
Code:
pass
finally:
 pipe ...  Popen() a shell
# >>> inner_product(a,operator.__add__,operator.__mul__,a)
else:
)
def integer_polynomial_generator(*args):
b'xi': b'u03BE',
if GCD(m,n) == 1:
# p = line(distance)
input += key[:max(0,32len(input)%32)] # make the input length a multiple of 32
>>> None
import pprint
octagonal_number = lambda n: n*(3*n2)
(rows,cols,) = newshape
vec([max(a[i],b[i])for i in range(len(a))]),
import decorator
signal.signal(signal.SIGALRM,self.trap_alarm)
return result()
<BLANKLINE>
def test_me(self):
print(ok)
return'\n'.join(['{']+['%s: %s'%(a,f(getattr(self,a)))for a in dir(self)if a[:2]!='__']+['}'])
a = [0,0]
# curr = cur with possibly repeated
def __ne__(self,other): return not (self == other)
# > filename or url, not  etc.
def test_bounding_box(self):
if 3 == c(v[0]):
[code]
Code tags[/code] are essential for python code and Makefiles!
October 16th, 2013, 03:15 AM

October 16th, 2013, 05:52 AM

Binary search won't help as a solution strategy. Binary searches work with ordered lists. There is no ordering here, just "yes the digit is correct" or "not so".
Right on with "basic python skill"!
[code]
Code tags[/code] are essential for python code and Makefiles!
October 16th, 2013, 06:06 AM

My fault, sorry, I did not read attentively. This game is quite different  something like MasterMind.
Looks I should invent the problem for my site for such game
However here is no check for "same digit but in wrong place"... Or I am inattentive again...
To post author: logic is even simpler  split your secret number into digit list (via "str" perhaps) and the number entered by guesser too. Then in a small internal loop check for the same digits at the same places...
October 16th, 2013, 06:35 AM

Hey, thank you all for a reply. Sorry to be such a bother but I really have no idea how to do it. I have no problems with c++ and html but only started studying python and i really don't get it. Thanks again. Is there perhaps a site that will tell me how to select specific digit and that will give me output y or n depending on if the number is right? (If that makes sense.)
October 16th, 2013, 06:40 AM

Then perhaps you will write it in C++ and then we could show you how to translate your ideas to python, so the whole thing would be much clearer to you...
October 16th, 2013, 06:42 AM

Originally Posted by rodiongork
Then perhaps you will write it in C++ and then we could show you how to translate your ideas to python, so the whole thing would be much clearer to you...
That certainly isn't a bad idea, as soon as I get home I will do as you say. Thanks again guys
October 16th, 2013, 07:52 AM

oh this ought to be fun.
Do it! Post your C++ code.
[code]
Code tags[/code] are essential for python code and Makefiles!
October 17th, 2013, 04:19 AM

Looks I should invent the problem for my site for such game
Ok, I kept promise and tried to create a problem with the same idea. However, it looks like this problem is bit more complicated comparing to original. Since it requires to write a program not for answering but for guessing... Perhaps I'll add simpler variant later.
Code Guesser at codeabbey.com
October 17th, 2013, 07:12 AM

I think, rodiongork, you're over working this problem. The program as I understand it picks 4 digits randomly, (not 5) 0 through 9. And then it scores guesses. Instead of printing digits it displays 'N' or 'Y' if that particular digit is correct. For now let's pretend the range of numbers is 09999 inclusive instead of 19999 without knowing whether the interval is open or closed.
For instance, if the random number chosen by the program were 1 and your first guess 0 the program should display, because the 0 digits are correct and only the rightmost digit is incorrect,
YYYN
Then your next guess would be 1 and the program would tell you you win!
The guesser can do no better than to start with 0 and increment the digits that are incorrect. The puzzle will always be solved by the tenth guess. The interesting question, which I've graphed but not analytically solved, is
"Given n digits, what is the mean maximum digit?" In other words, for a generalized puzzle what is the average number of guesses?
Hmmm. If the puzzle were binary the answer would involve 2**(n) as the probability the game takes 2 guesses.
[code]
Code tags[/code] are essential for python code and Makefiles!
October 17th, 2013, 08:55 AM

Oh, I failed to notice that 'Y' or 'N' should be shown for each particular digits.
Given n digits, what is the mean maximum digit?" In other words, for a generalized puzzle what is the average number of guesses?
Wow!
I agree, it is interesting problem, though I do not know whether it could be beautifully expressed with analytic formula.
As I see, given N digits in Kbased numeral system we have:
K^N variants,
of them
(K^N  (K1)^N) for digit K  1
((K1))^N  (K2)^N) for digit K  2
...
and 1 for digit 0
This should be multiplied and summed... I'll see whether it could be reduced to some simple formula %)
UPD
Oh, I see, this gives:
(K1)*K^N  (K1)^N  (K2)^N  (K3)^N  ...  1
 divided by 
K^N
I fear the tail of the numerator is some wellknown formula, but not with any beautiful reduction...
Comments on this post