This week’s mini-project in my Coursera Python class was to create a Guess The Number game, where the program selects a random number in a specified range (either 0-100 or 0-1000 at the player’s discretion), and the player guesses, with the program saying Higher or Lower until the player guesses correctly, or runs out of guesses.
It was a fairly basic program. We used GUI elements for the first time. Two quibbles/annoyances: Event handlers, which to me seem the same as functions. Why call them something different? It’s just a function called by an event, isn’t it? Maybe I’m missing something, and the rest of the course will clarify and show me how event handlers are distinct from functions.
The second quibble is with the course: For GUI elements, they use SimpleGUI, which is a module created especially for the class, and doesn’t exist otherwise. I would have preferred a module we could use outside the class, like tkinter. I don’t know anything about them, and would like to apply what I learn elsewhere. It seems like I’ll have to learn tkinter or something like it outside the class.
I’ll post a link to my game once the submission period for grading is over. If you are taking the class and have a question, let me know via the comments and I’ll do my best to help.
I a in this class as well but I am lost in getting started can you give me some tips
You’ll need to define your variables, to store the limit of the game (100 or 1000, I called mine limit), the random number the program will choose (I called it secret_number), and the maximum number of guesses (max_guesses). In your main event handler/function you will need to take the input from the user, and compare it to the secret number to see if they guess right, or if the secret number is higher or lower, then print the result. It will also need to reduce the number of guesses by one until it hits zero, ending the game and starting a new one.
Two other event handlers (the buttons) will set the range at either 100 or 1000, by updating the limit variable and resetting the others to start new. I hope this helps. Let me know what area you are having trouble with.
hi there! i’am new to programming in general not ony in python and i can’t make the function get_input (guess ) to work. I think i have all the code but it don’t print anything in the console.
Do you get the input box? Do you have a print command to print the result?
yes, i thing i know what i did wrong, i split the main directions: i write the number of oportunities to guess in range100 (but it’s wrong right?) and the other part (lower, higher number) in get_input(guess). But everything goes in the last one right?
Right. The range event handlers should only set the range and reset, nothing else.
Thanks a lot!!
me again! i can run the programm now but i have a problem i don’t know what i have to put in the () in get_input here : def range1000():
get_input()
init()
I know that the parameter is guess but i don’t know hte value unless the user enter it.
Hi Lucia – You need to register the event handler to pass the input from the user into your guess parameter. If you defined your event handler as get_input(guess), then you’d register it with something like inp = frame.add_input(“Enter guess.”, get_input, 100)
I hope this helps.
Hi Lucia. If you want, I’d be happy to look at your code. I know the submission deadline is over, but I’m happy to help if you’d like.
thanks! when i was evaluating classmates i understand what i did wrong. I don’t have background in programming (i’m a biological scientist) and the course is starting to be a bit difficult to follow.
Thank you so much. I am a student of 2013 online course and I would like to know how to use the input (guess_number) for multiple times to compare with the secret_number?