lost how to use easygui

Metalrocks

Distinguished
Nov 13, 2014
244
2
18,685
programming is really not my thing.
we use python and wing to write the codes.

for weeks now i have tried to master this "magic game" and i cannot get it to work. originally i had a functioning game that worked fine within python but my lecturer wants me that i use this easygui and now things are a mess. i really hope someone can help me out here because its utter frustrating that i nearly failed an exam because of this.

thats what i have so far:

# This is a guess the number game.
import easygui as eg
answer = eg.enterbox('What is your name?')
eg.enterbox('OK, '+answer + '! Guess a number between 1 and 10')
#eg.enterbox ("Guess a number between 1 and 10:")


import random

guessesTaken = 0

#print('What is your name?')


number = random.randint(1, 10)
#print('OK, ' + myName + ', Guess a number between 1 and 10')

while guessesTaken < 1:
#print('Guess.') # There are four spaces in front of print.
answer = eg.enterbox('')
guess = int(number)



guessesTaken = guessesTaken + 3

if guess < number:
eg.enterbox('Too low. Try again.') # There are eight spaces in front of print.

if guess > number:
eg.enterbox('Too high. Try again.')

if guess == number:
break

if guess == number:
guessesTaken = str(guessesTaken)
eg.msgbox('Well done young Padawan. You guessed ' + guessesTaken + ' times!')

if guess != number:
number = str(number)
eg.msgbox('No. The number was ' + number)

 
Solution
Good.

That is the level of effort that is often required with respect to coding, networking, websites, etc.

You learn the syntax and the logic. Putting it all together into workable code and an end product is the more demanding task.

"Cookbook" examples are the pieces that you must understand, modify, and combine to achieve the end goal.

Hopefully you learned a few other things and gained a better understanding of it all.

Use and apply that additional knowledge and experience in the website class. Do not look for answer "C" per se. But how you might combine "A" and "B" to arrive at "C".

Ralston18

Titan
Moderator
Full disclosure: Not a Python programmer nor easygui user.

However, your code is basically followable and the exercise is a common teaching assignment.

That said I see both logic problems and some conflicting syntax. (One hint: increment for guessesTaken....?)

LOGIC:

Draw a box for each variable and input. E.g, answer, guess, number, guessesTaken, etc.

Pretend you are a computer.

Walk through your code and do exactly what the code tells the computer.

Write values in the appropriate boxes. Follow the conditionals thereafter going through the loops. As values and answers change, update the boxes.

Step by step.

Correct your code as warranted.

GUI:

Once you have the logic restored (per your earlier functioning game) then begin again and implement the GUI interface step by step.

I think you have all of the pieces to a large extent. Just a bit jumbled up so be methodical and go step by step. Do not proceed until the current step is working correctly.
 

Metalrocks

Distinguished
Nov 13, 2014
244
2
18,685
thats the problem. i have no idea how to implement them and where. im really struggling to master this subject. all i want so have this crap finished so i can focus on more importation stuff that matter to me at uni.
 

Ralston18

Titan
Moderator
Forum rules do not allow members to do homework. We can hint and suggest but the work must be yours.

Your choice of words and phrasing suggests that maybe you are struggling because you really do not want to do it, have lost interest, or have other stresses.

Unfortunately, as in many things, logic and coding is something that must simply be worked through. And it can be very frustrating at any level.

Persistence is a learned skill for many people.

20% of the task can cause 80% of the problems.....

In the meantime, because I am the curious sort, I looked into EasyGUI.

Found this:

http://easygui.sourceforge.net/cookbook.html

You may find it useful to visit the link and check out some of the other information, tutorials, and examples that are available.

Maybe the result will be one of those "Eureka" moments.



 

Metalrocks

Distinguished
Nov 13, 2014
244
2
18,685
i fail to understand its logic of this subject. it makes no sense with its coding. and im not the only one in class who doesnt get it. more than half in my class fail to understand this stuff and we have pointed it out to our lecturers that we still dont get it how it helps us in life.
since day 1 me and many others fail to comprehend it and doesnt matter how we ask the question or read through all of the infos provided, nothing makes sense.

the link does give me some infos but cant see how it helps me with my problem. thanks anyway for your help. still open to suggestion until i have this damn crap finished.

edit. ok, my lecturer helped me out a bit and now it works almost fine. the only mistake i have that when i enter letters in to the field that should be numbers, it crashes. and i have forgotten how i can enter it in that does does respond to it.
the error refers to this line here:
guess = int(answer)

now this should not violate the rule to tell me what i have to enter to make the whole program work. because google or that link helped me.
 

Ralston18

Titan
Moderator
You will need to design and code an error routine that looks at the "answer" and detects if the user has entered a non-numeric response.

And if that has happened then generates a response to the user to enter a number/numeric value.

Common enough function in coding where expected user inputs must meet some criteria or range of values, may be only Y(y) or N(n), and so forth.

The clue I will offer (and the moderators can "edit" as warranted) is that you need to determine how to recognize whether a number, letter, or special character has been typed in by the user when responding to the answer box.

I just looked and easily found a way to do just that. Guess where I looked... :)
 

Metalrocks

Distinguished
Nov 13, 2014
244
2
18,685
thanks. i did use google before i have posted my issue here and found a site that showed all kinds of methods. just finding one that worked took me some time because none of them really explained my case too well. but most likely because i generally didnt understand anything.
my lecturer later on helped me out a bit that i got things right.

now this crap is finished. next week we start to create websites, and i hope this coding stuff makes far more sense to me than this.
 

Ralston18

Titan
Moderator
Good.

That is the level of effort that is often required with respect to coding, networking, websites, etc.

You learn the syntax and the logic. Putting it all together into workable code and an end product is the more demanding task.

"Cookbook" examples are the pieces that you must understand, modify, and combine to achieve the end goal.

Hopefully you learned a few other things and gained a better understanding of it all.

Use and apply that additional knowledge and experience in the website class. Do not look for answer "C" per se. But how you might combine "A" and "B" to arrive at "C".
 
Solution

TRENDING THREADS