So, I suck shit at programming. As a result, I'm using Python and EasyGUI.
Anyways, I've made this simple program in which you type in the number of your coins of each type (e.g. 0.10 cents etc), and it calculates the sum for you.
Now, I have 2 questions about this:
If I type letters, it crashes. That's expected, since the program wants numbers. How can I make it so it doesn't let me type in letters?
Also, I'm using a seperate messagebox for each type of coin, each appearing after the previous is done. I know EasyGUI can do multiple inputboxes but it just doesn't work out for me.
Here's my source code:
[code]import sys
from easygui import *
msg="Welcome!";
title="Speel's Coins"
choices=["Begin"]
choice=indexbox(msg,title,choices)
def input_numbers(): #a function to take input
global ten,twenty,fifty,one,two,sumten,sumtwenty,sumfifty,sumone,sumtwo,sumall
ten=float(enterbox(msg='How many 0.10E coins do you have?', default='0'))
twenty=float(enterbox(msg='How many 0.20E coins do you have?', default='0'))
fifty=float(enterbox(msg='How many 0.50E coins do you have?', default='0'))
one=float(enterbox(msg='How many 1.00E coins do you have?', default='0'))
two=float(enterbox(msg='How many 2.00E coins do you have?', default='0'))
sumten=(ten * 0.10)
sumtwenty=(twenty * 0.20)
sumfifty=(fifty * 0.50)
sumone=(one * 1)
sumtwo=(two * 2)
sumall= sumten + sumtwenty + sumfifty + sumone + sumtwo
input_numbers()
result = sumall
if 10 < result < 29:
msgbox("Nice! %s E! Have fun spending!"%result)
elif result < 10:
msgbox("You didn't make much. %s E."%result)
else:
msgbox("Woah, you have %s E in coins!?"%result)
[/code]
do something like a
[code]
try:
one=float(enterbox(msg='How many 1.00E coins do you have?', default='0'))
except:
msgbox("Please enter a number")
[/code]
You can work out from there how to make it loop until you get a number input.
Also your coding style is really unreadable. Try looking at this: [url]http://www.python.org/dev/peps/pep-0008/[/url]
Also, get into the habit of doing:
[code]
import easygui
easygui.enterbox()
[/code]
If you move on to bigger things it means you dont get conflicts between functions.
Alright, thanks! What about the mutliple inputboxes?
Sorry, you need to Log In to post a reply to this thread.