Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63870
| References | <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> |
|---|---|
| Date | 2014-01-14 14:12 +1100 |
| Subject | Re: Tkinter GUI Error |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5435.1389669132.18130.python-list@python.org> (permalink) |
On Tue, Jan 14, 2014 at 5:49 AM, <fluttershy363@gmail.com> wrote: > entry = entry1var.get() > if entry == num1: > elif entry > num1: > elif entry < num1: > > num1 =str(random.randint(10,99)) > num2 =str(random.randint(10,99)) > num3 =str(random.randint(10,99)) > mastercode = num1+num2+num3 Be careful of code like this. You've specified that your three parts range from 10 through 99, so this will work as long as the user knows this and enters exactly two digits. Doing inequality comparisons on strings that represent numbers will work as long as they're the same length, but if the lengths vary, the string comparisons will start at the beginning - not what most people will expect. These are all true: "2" > "10" "3.14159" > "2,000,000" "42" < "Life, the universe, and everything" "00012" < "12" If your intention is to have a six-digit number, you could simply ask for one, and then format the pieces accordingly: num = random.randint(1,999999) num_str = "%06d" % num You can then slice up num_str as needed (it'll have leading zeroes if it needs them), or you can do numerical comparisons against num itself. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Tkinter GUI Error fluttershy363@gmail.com - 2014-01-13 10:49 -0800
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-13 10:51 -0800
Re: Tkinter GUI Error Christian Gollwitzer <auriocus@gmx.de> - 2014-01-13 20:03 +0100
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-13 11:21 -0800
Re: Tkinter GUI Error Peter Otten <__peter__@web.de> - 2014-01-13 20:36 +0100
Re: Tkinter GUI Error Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-13 20:39 -0500
Re: Tkinter GUI Error Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-13 18:47 -0800
Re: Tkinter GUI Error Chris Angelico <rosuav@gmail.com> - 2014-01-14 14:12 +1100
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-14 11:11 -0800
Re: Tkinter GUI Error Lewis Wood <fluttershy363@gmail.com> - 2014-01-14 13:27 -0800
Re: Tkinter GUI Error Christian Gollwitzer <auriocus@gmx.de> - 2014-01-14 22:33 +0100
csiph-web