python3
Hi I am trying to compare these two (strings) of numbers.

There may not be a space inbetween the numbers in the file, but here its just for clearity.
I want to take the value of 40 and compare it with 14 then 18,35 and so on until 54 is reached.
(The 07 and 57 would be compared afterwords.)for now I am trying to understand how to reach these other numbers.

``````comp_b = open("C:\output.txt","r")
``````

The output of this code is s=14

14 18 35 47 54 - 57

40 45 49 53 57 - 07

``````comp_b = open("C:\output.txt","r")
s1 = comp_b.read(*The part I don't know*)
``````

I would rather have s=40 first.
So as it is, I don't know the best way to get s=40 then s1=14, then compare s/s1 for equality. yes/no
Afterword' I would compare 40 too 18,35,47,54 in the same manner.
Thanks for any guidlines to this.

## All 25 Replies

A hint:

``````>>> line = '14 18 35 47 54 - 57\n'
>>> line.split()
['14', '18', '35', '47', '54', '-', '57']
``````

so the line splits to 5

ext....

Do you know what a python list is ? Read this example about reading a data file line by line and manipulate its content.

I can s[1] but its not giving me a double digit return

s[2:4]
'09'

s[4:8]
' 12 '
ok I'm getting close I guess

s[2:4]equaled the first one 09
and s[4:8] equaled the second one 12
next one did'nt work, So I have no idea how to pick out the specific number. oh i got s[8:10]=33 but I guessed still dont know how.
s[10:14]= 37 got this one and the last one also s[14:16]=52
and the last one s[19:22]=' 46' oh extra space s[20:22]='46'
ok thanks alot for the little puzzle:)

It is very informative though I don't understand it all.
Example: This file
06 15 26 34 36 - 16
16 24 30 34 43 - 20

`compare= open("C:\output.txt","r")`
`s=compare.readline()`
`s.split()`
Output:equals this.
`['06', '15', '26', '34', '36', '-', '16']`
Then I did this.
`t=compare.readline()`
`t.split()`
Output:equals this.
`['16', '24', '30', '34', '43', '-', '20']`
Then I did this.
`print(t[0:3] in s)`
wich output:
`False`
Ok False is desired, since the last 16 is compared differently
But I dont know why it came out <False> when <16> is in <s>
Or is it I don't know.
it turns true if I place 16 say like this in the file.

``````06 15 16 34 36  - 26
16 24 30 34 43  - 20
``````

`

Some hint.

``````>>> s = ['06', '15', '26', '34', '36', '-', '16']
>>> t = ['16', '24', '30', '34', '43', '-', '20']
>>> s[0]
'06'
>>> t[0]
'16'
>>> s[0] == t[0]
False
>>> s[3] == t[3]
True
>>> s[5] == t[5]
True
``````

But I dont know why it came out <False> when <16> is in <s>

``````>>> t[0:3]
['16', '24', '30']
>>> t[0:3] in s
False

>>> #To make it True
>>> s = [['16', '24', '30'],'06', '15', '26', '34', '36', '-', '16']
>>> t[0:3] in s
True
``````

You are checking if list ['16', '24', '30'] is in s and that is False.

Iterate over both list and compare.

``````>>> s = ['06', '15', '26', '34', '36', '-', '16']
>>> t = ['16', '24', '30', '34', '43', '-', '20']
>>> for x,y in zip(s, t):
print x == y

False
False
False
True
False
True
False
``````

Or make it a list,with use of comprehension.

``````>>> [x == y for x,y in zip(s, t)]
[False, False, False, True, False, True, False]
``````

Yes, you must learn to manipulate python's container data types: lists, sets, dicts. You can do many things with your data

``````a = ['06', '15', '26', '34', '36', '-', '16']
b = ['16', '24', '30', '34', '43', '-', '20']

xa = a[:-2] # take all elements but the last 2 ones
xb = b[:-2]

nl = '\n'
print(xa, xb, sep = nl)
"""
['06', '15', '26', '34', '36']
['16', '24', '30', '34', '43']
"""

ya = set(xa) # build unordered sets instead of lists
yb = set(xb)
print(ya, yb, sep = nl)
"""
{'15', '26', '34', '06', '36'}
{'16', '43', '34', '24', '30'}
"""
print(ya & yb)
print(ya - yb)
print(yb - ya)
print(ya == yb)
"""
{'34'} # elements in ya and yb
{'15', '26', '36', '06'} # items in ya but not in yb
{'16', '30', '43', '24'} # items in yb but not in ya
False # the 2 sets are different
"""
lasta = a[-1] # take the last numbers
lastb = b[-1]
print(lasta, lastb, lasta == lastb, sep = nl)
"""
16
20
False
"""
``````

I did this and tested it for the six number to flaw and it never did after 100's of tries. So I think this works for one set of numbers
with sixth number as powerball.

This is the file output however the program generates these as random numbers.
you can see the first number is 01 this 01 has no bearing on the sixth 01 on the first line, as far as I'v tested it.
so all the prints will come out False if you run it.

31 43 45 57 58 - 01
01 13 21 22 40 - 29

This should equal:One True for the 40 match the rest would be False:

31 40 45 57 58 - 01
01 13 21 22 40 - 31

``````comp= open("C:\output.txt","r")
s.split()
print('The draw number is', s)

t.split()
print('The win number is', t)
print(t[0:3] in s)
print(t[2:5] in s)
print(t[6:8] in s)
print(t[8:11] in s)
print(t[12:15] in s)

comp.close()
return
``````

I never compared the sixth numbers yet but it looks like you have above I will get to it soon ie:copy & paste :)
If you can Please test this for me and let me know if it is adequate.

You can do this `print(t[0:3] in s)` read my post again.

You are checking if list ['16', '24', '30'] is in s and that is False.

And see how i make it True.

This should equal:One True for the 40 match the rest would be False:

31 40 45 57 58 - 01
01 13 21 22 40 - 31

You have to make a rule for this.
Because there are 4 elements that's in both list.

``````>>> s = '31 40 45 57 58 - 01'.split()
>>> t = '01 13 21 22 40 - 31'.split()
>>> [item for item in t if item in s]
['01', '40', '-', '31']

>>> #Or with set() as Grib posted
>>> ys = set(s)
>>> yt = set(t)
>>> print(ys & yt)
set(['31', '01', '-', '40'])
``````

you can see the first number is 01 this 01 has no bearing on the sixth 01 on the first line

I guess the same is for 31,then you can take away last 2 element.

``````>>> s = '31 40 45 57 58 - 01'.split()[:-2]
>>> s
['31', '40', '45', '57', '58']
>>> t = '01 13 21 22 40 - 31'.split()[:-2]
>>> t
['01', '13', '21', '22', '40']
>>> [item for item in t if item in s]
['40']

>>> ys = set(s)
>>> yt = set(t)
>>> print(ys & yt)
set(['40'])
``````

This should equal:One True for the 40 match the rest would be False:

So as in code over one True match(40) that are in both list.

Wow! you guys realy lost me, I have'nt realy got to this level.
So I don't understand what you did.
From what I try to understand, is that you separated the last sixth digits from the rest and compared them seprately.and returned True\False
though I can't read the prints enouph to comprehend them.

``````{'-', ' ', '9', '8', '1', '3', '2', '4', '7'}
{'-', ' ', '9', '8', '1', '2', '4', '7'}
{'5'}
{'3'}{'-', ' ', '9', '8', '1', '2', '5', '4', '7'}
``````

So I don't understand what you did.

Your initial question is ambiguous. You're describing what you want to do, instead of describing the information you need.

It would be easier if you tell us exactly what you want from the lists

x0 x1 x2 x3 x4 - x5
y0 y1 y2 y3 y4 - y5

For example "I want the list of items in x0 x1 x2 x3 x4 which belong to y0 y1 y2 y3 y4". That would be

``````a = ['06', '15', '26', '34', '36', '-', '16']
b = ['16', '24', '34', '30', '43', '-', '20']

result = list(set(b[:5])& set(a[:5]))
``````

or "I want the list of integers i for which a[i] and b[i] are equal". That would be

``````m = min(len(a), len(b))
indexes = [i for i in range(m) if a[i] == b[i]]
``````

What I want is to compare each record at a time starting with
13 27 34 41 47 - 49 compared with 07 13 14 23 45 - 07
This would generate True or False for matching numbers. I would then evaluate the True for a prizefor each set. Example: four True would equal = \$7.00 and If all numbers match It would be a jackpot of many millions.

I then would procede to the next record 22 24 45 46 51 - 15 and compare it to 07 13 14 23 45 - 07.....
I would then compare the last record 12 23 40 47 57 - 04
and compare it for a prize.
Then delete the file, or its contents.
This is what I am trying to get from this data.

So the info I need is how to compare each record list.
13 27 34 41 47 - 49
22 24 45 46 51 - 15
10 14 22 25 42 - 13
01 04 17 31 52 - 38
12 23 40 47 57 - 04

07 13 14 23 45 - 07

``````So so far the program looks like this

from tkinter import*
import sys, random, tkinter
ticket_price = 2
i=0
total  = 0
text1=0
drawing2=''
drawing=''

def calculatetotals():
valid = set('12345')
ticket_entry = tik.get()
if ticket_entry not in valid:
print('We permit values in {}.'.format(valid))
label4 = Label(aApp,text = 'We permit values in 1, 2, 3, 4 or 5!',fg = 'blue').grid(row=7,column=1)
else:
label4 = Label(aApp,text = '                                                                        ',fg = 'blue').grid(row=7,column=1)
mytik=int(ticket_entry)
total = mytik*ticket_price
Label(aApp,text= "You purchased:\$%.2f \n" %  total).grid(row=7,column=1)
Label(aApp,text= "\nNumber Of Tckets: %.f\n" % mytik).grid(row=6,column=1)
,command = nextx).grid(row=8,column=1)
aApp=Tk()
aApp.geometry('580x170+200+270')
aApp.title("LOTTO")
tik=StringVar()
label1 = Label(aApp,text = "Welcome To Lotto.",fg = 'blue')
label1.grid(row=0,column=2)
label2=Label(aApp,text="Tickets Are \${:.2f} Each.".format(ticket_price),fg='red')
label2.grid(row=1,column=1)
label3=Label(aApp,text="How Many Would You Like?",fg='black')
label3.grid(row=2,column=1)
mytik = Entry(aApp,textvariable=tik)
mytik.grid(row=2,column=2)
,command=calculatetotals)
button1.grid(row=6,column=1)

def nextx():

,command = nextz).grid(row=8,column=1)
ticket_entry = tik.get()
#######################################
# outputs to Window and File("C:\output.txt","a")
#######################################
i = 0

while i < int(ticket_entry):
L = list(range(1,60))
random.shuffle(L)

g = L[:5]
g.sort()
f = L[5:6]
drawing = ' '.join( [' '.join (zstr(G) for G in g),' -',zstr(f[0])])

comp_a = open("C:\output.txt","a")
comp_a.write('\n')
comp_a.write(drawing)
i+=1

#########################################
# Finnished output to window and File
#########################################
app=tkinter.Tk()
app.geometry('600x400+75+75')
app.title(string="     NUMBERS      ")

Button(app, text="Quit", command=app.quit).pack()
def  nextz():
Button(aApp,text='Push   again to  <Quit> : To see if you match Push <Compare> In The New Winning Number Window, '\
,fg='yellow',bg='black',command = quit).grid(row=8,column=1)
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
drawing2 = ' '.join( [' '.join (zstr(G) for G in g),' -',zstr(f[0])])

aBpp=tkinter.Tk()
aBpp.geometry('200x100+705+705')
aBpp.title(string="Winning Number")
Button(aBpp, text="quit", command=aBpp.quit).pack()
Button(aBpp, text="Compare", command=compare).pack()

#comp_b = open("C:\output.txt","a")
#comp_b.write('\n')
#comp_b.write(drawing2)
#print ('\n',drawing2)
#comp_b.close()
return
def compare():

#comp= open("C:\output.txt","r")

return

def zstr(ob, width = 2):
return '{x:0>{width}s}'.format(x = str(ob), width = width)

tkinter.mainloop()
app.mainloop()
aApp.mainloop()
``````

This is the program so far.
I know it has MANY flaws though as it is it works up to the COMPARE button.

``````from tkinter import*
import sys, random, tkinter
ticket_price = 2
i=0
total  = 0
text1=0
drawing2=''
drawing=''

def calculatetotals():
valid = set('12345')
ticket_entry = tik.get()
if ticket_entry not in valid:
print('We permit values in {}.'.format(valid))
label4 = Label(aApp,text = 'We permit values in 1, 2, 3, 4 or 5!',fg = 'blue').grid(row=7,column=1)
else:
label4 = Label(aApp,text = '                                                                        ',fg = 'blue').grid(row=7,column=1)
mytik=int(ticket_entry)
total = mytik*ticket_price
Label(aApp,text= "You purchased:\$%.2f \n" %  total).grid(row=7,column=1)
Label(aApp,text= "\nNumber Of Tckets: %.f\n" % mytik).grid(row=6,column=1)
,command = nextx).grid(row=8,column=1)
aApp=Tk()
aApp.geometry('580x170+200+270')
aApp.title("LOTTO")
tik=StringVar()
label1 = Label(aApp,text = "Welcome To Lotto.",fg = 'blue')
label1.grid(row=0,column=2)
label2=Label(aApp,text="Tickets Are \${:.2f} Each.".format(ticket_price),fg='red')
label2.grid(row=1,column=1)
label3=Label(aApp,text="How Many Would You Like?",fg='black')
label3.grid(row=2,column=1)
mytik = Entry(aApp,textvariable=tik)
mytik.grid(row=2,column=2)
,command=calculatetotals)
button1.grid(row=6,column=1)

def nextx():

,command = nextz).grid(row=8,column=1)
ticket_entry = tik.get()
#######################################
# outputs to Window and File("C:\output.txt","a")
#######################################
i = 0

while i < int(ticket_entry):
L = list(range(1,60))
random.shuffle(L)

g = L[:5]
g.sort()
f = L[5:6]
drawing = ' '.join( [' '.join (zstr(G) for G in g),' -',zstr(f[0])])

comp_a = open("C:\output.txt","a")
comp_a.write('\n')
comp_a.write(drawing)
i+=1

#########################################
# Finnished output to window and File
#########################################
app=tkinter.Tk()
app.geometry('600x400+75+75')
app.title(string="     NUMBERS      ")

Button(app, text="Quit", command=app.quit).pack()
def  nextz():
Button(aApp,text='Push   again to  <Quit> : To see if you match Push <Compare> In The New Winning Number Window, '\
,fg='yellow',bg='black',command = quit).grid(row=8,column=1)
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
drawing2 = ' '.join( [' '.join (zstr(G) for G in g),' -',zstr(f[0])])

aBpp=tkinter.Tk()
aBpp.geometry('200x100+705+705')
aBpp.title(string="Winning Number")
Button(aBpp, text="quit", command=aBpp.quit).pack()
Button(aBpp, text="Compare", command=compare).pack()

#comp_b = open("C:\output.txt","a")
#comp_b.write('\n')
#comp_b.write(drawing2)
#print ('\n',drawing2)
#comp_b.close()
return
def compare():

#comp= open("C:\output.txt","r")

return

def zstr(ob, width = 2):
return '{x:0>{width}s}'.format(x = str(ob), width = width)

tkinter.mainloop()
app.mainloop()
aApp.mainloop()
``````

Again we don't know precisely the information that you need. Apparently, your numbers are ordered (but the last number), so I suppose that you treat the first 5 numbers as a set rather than a list. Here is a piece of code which computes a score function for each line by comparing the line to the target line. The score is a pair of numbers (n, m), where n
is the number of correct guesses among the 5 first numbers, and m is 0 or 1 depending on
the last number (1 if it matches the target, 0 otherwise). I'm sure you can use this score function in your code.

``````data = [line.split() for line in """
13 27 34 41 47 - 49
22 24 45 46 51 - 15
10 14 22 23 42 - 13
01 04 17 31 52 - 38
12 23 40 47 57 - 04
""".strip().splitlines()]

target = "07 13 14 23 45 - 07".split()

print(data)
print(target)

def score(a, b):
return (len(set(a[:5]) & set(b[:5])), 1 if (a[-1] == b[-1]) else 0)

print()
for a in data:
print(a, score(a, target))

""" my output -->
[['13', '27', '34', '41', '47', '-', '49'], ['22', '24', '45', '46', '51', '-', '15'], ['10', '14', '22', '23', '42', '-', '13'], ['01', '04', '17', '31', '52', '-', '38'], ['12', '23', '40', '47', '57', '-', '04']]
['07', '13', '14', '23', '45', '-', '07']

['13', '27', '34', '41', '47', '-', '49'] (1, 0)
['22', '24', '45', '46', '51', '-', '15'] (1, 0)
['10', '14', '22', '23', '42', '-', '13'] (2, 0)
['01', '04', '17', '31', '52', '-', '38'] (0, 0)
['12', '23', '40', '47', '57', '-', '04'] (1, 0)
"""
``````

ok I understand this code I can just adapt it to read from a file.

I don't know how to adapt from the File output.txt

``````data = open("C:\output.txt","r")
data= [line.split() for line in
.strip().splitlines()]
target = comp_b.split()
print(data)
print(target)
def score(a, b):
return (len(set(a[:5]) & set(b[:5])), 1 if (a[-1] == b[-1]) else 0)
print()
for a in data:
print (a, score(a, target))
``````

I did this and got some data but not the comparision.
Iam still not able to read the target variable from the file and had to put it in as data
as you did.

`````` "target = '07 13 14 23 45  -  07'.split()"

def compare ( ) :

comp_a= open("C:\output.txt","r")
data=[line.split() for line in comp_a]
target = '07 13 14 23 45  -  07'.split()
print(data)
print(target)
comp_a.close()

def score(a, b):
return (len(set(a[:5]) & set(b[:5])), 1 if (a[-1] == b[-1]) else 0)
print()
for a in data:

print(a,  score(a,  target))
``````

I don't know, it seems that you are copying and pasting code without understanding it. It can't work this way. Your code is not properly indented with 4 spaces. I gave you the link to Tim Peter's reindent script, why don't you use it to clean your program, and configure your editor to indent with 4 spaces ? Also your Tkinter program doesn't need 3 calls to mainloop(). Normally only one call is needed. It means that you don't understand what mainloop does. etc. I think you want to go too fast, but you should read a python tutorial such as dive into python 3.

Ok I have tried to fix some of the indents
So far this code should work minus the errors with tk frame stuff
it should work as far as the math.
however i still don't know how to utilize the bold code below to grab
value of a prize example

``````(3,0),(1,1),(2,1),(3,1)
``````

are all winners
I don't know how to use the values though
If I print(score)

I get:

``````<function compare.<locals>.score at 0x00FA2C48>
``````

or I would get an error saying I cant compare int to str
So what variable or vallue does

``````(3,1)
``````

or any of the obove have?
and how can i compare them?

also I want to use only this program to learn some of the basics of python3, after it is finnished and works.
So this is why I use copy/paste and error running.
So I know it has many flaws.
Thanks for any help.

``````**def score(a, b):
return (len(set(a[:5]) & set(b[:5])), 1 if(a[-1] == b[-1]) else 0)
print()
for a in s:
print(a, score(a, target))
**

from tkinter import*
import sys, random, tkinter
ticket_price = 2
i=0
g=''
total  = 0
comp_a=' '
comp_b=' '
score=0
drawing2=''
drawing=''
target=''
s=''
sx=' '
a=''
b=''
def calculatetotals():
valid = set('12345')
ticket_entry = tik.get()

if ticket_entry not in valid:
print('We permit values in {}.'.format(valid))
label4 = Label(aApp,text = 'We permit values in 1, 2, 3, 4 or 5!',fg = 'blue').grid(row=7,column=1)
else:
label4 = Label(aApp,text = '                                                                        ',fg = 'blue').grid(row=7,column=1)
mytik=int(ticket_entry)
total = mytik*ticket_price
Label(aApp,text= "You purchased:\$%.2f \n" %  total).grid(row=7,column=1)
Label(aApp,text= "\nNumber Of Tckets: %.f\n" % mytik).grid(row=6,column=1)
,command = nextx).grid(row=8,column=1)

aApp=Tk()
aApp.geometry('600x400+75+75')
aApp.title("LOTTO")

tik=StringVar()
label1 = Label(aApp,text = "Welcome To Lotto.",fg = 'blue')
label1.grid(row=0,column=2)
label2=Label(aApp,text="Tickets Are \${:.2f} Each.".format(ticket_price),fg='red')
label2.grid(row=1,column=1)
label3=Label(aApp,text="How Many Would You Like?",fg='black')
label3.grid(row=2,column=1)
mytik = Entry(aApp,textvariable=tik)
mytik.grid(row=2,column=2)
,command=calculatetotals)
button1.grid(row=6,column=1)

def nextx():
,command = nextz).grid(row=8,column=1)
ticket_entry = tik.get()
i = 0

while i < int(ticket_entry):
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
drawing = ' '.join( [' '.join (zstr(G) for G in g),'-',zstr(f[0])])
label5=tkinter.Label(aApp,text = drawing)
label5.pack(fill=X)

comp_b = open("C:\output.txt","a")
s = comp_b.write(drawing)
s=comp_b.write('\n')
s = [line.split() for line in sx.strip().splitlines()]
i+=1

def  nextz():
Button(aApp,text='Push   again to  <Quit> : To see if you match Push <Compare> In The New Winning Number Window, '\
,fg='yellow',bg='black',command = quit).grid(row=8,column=1)
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
global drawing2
global target
drawing2 = ' '.join( [' '.join (zstr(G) for G in g),'-',zstr(f[0])])
target=drawing2

aBpp=tkinter.Tk()
aBpp.geometry('200x100+705+705')
aBpp.title(string="Winning Number")
Button(aBpp, text="quit", command=aBpp.quit).pack()
Button(aBpp, text="Compare", command=compare).pack()

def zstr(ob, width = 2):
return '{x:0>{width}s}'.format(x = str(ob), width = width)

def compare ():
s=''
comp_a = open("C:\output.txt","r")
s = [line.split() for line in s.strip().splitlines()]
target = drawing2.split()
print('Purchased Numbers are',s)
print('Win Number is ',target)

def score(a, b):
return (len(set(a[:5]) & set(b[:5])), 1 if(a[-1] == b[-1]) else 0)
print()
for a in s:
print(a, score(a, target))
comp_a.close()

killfile = open("C:\output.txt","w")
killfile.close()

tkinter.mainloop()
app.mainloop()
aApp.mainloop()
``````

You could try something like this ...
(that uses the code given you by @Gribouillis ... slightly revised ... and with comments added that may help explain it for you.)

``````filename = 'myData.txt'
'''
07 13 14 23 45 - 04
13 27 34 41 47 - 49
22 24 45 46 51 - 15
10 14 22 23 42 - 13
01 04 17 31 52 - 38
12 23 40 47 57 - 04
'''

def score(i, t): # i = items_set, t =target_set
# returns number of items in intersection set of target & item sets
# also returns True or False indicating if the last items match
return ( len( set(i[:5]) & set(t[:5]) ), i[-1] == t[-1] )

import fileinput as fin

text1 = '(Number of Items in Intersection,'
text2 = ' Last Items do Match?)'
stars = [ ' *' for i in range(5) ] + [ '-', ' *']

i = 0
for line in fin.input( filename ):
items = line.split()
if i == 0:
target = items
print( 'Target' )
print( items )
print( '\nItems', ' '*4, text1, text2  )
print( stars, ' *, ***** ' )
else:
print( items, score(items, target) )
i += 1

input()
``````

ok This did not work or I did it wrong
if I have results like this (3,1) I am looking for a comparision
variable like (a,b)like if a=>3 and b>0 =\$5.00 add \$5.00 to a win variable.
in otherwords I cant manipulate (3,1) and I am asking how it is done
not with code ,though it is helpfull, just verbaly.
Thank you for you help.The output of the program is this:

Win Number is ['12', '25', '34', '42', '59', '-', '19']
['16', '34', '45', '50', '56', '-', '36'] (1, 0)
['02', '06', '14', '17', '39', '-', '33'] (0, 0)
this would be a loss. I don't know how to determine it a loss
So I can print 'You did not win this time'

Win Number is ['12', '25', '34', '42', '59', '-', '19']
['12', '25', '34', '42', '59', '-', '19'] (5, 1)
['02', '06', '14', '17', '39', '-', '33'] (0, 0)
This would be a jackpot and a loss I would print 'You won the jackpot'

Hi i have been using this site for info I dont think it is python 3 but it is helpful to me because its layout.

``````http://www.java2s.com/Code/Python/2D1.htm
``````

So far this all works, almost just the way I want it to.
I am having problems with the code below
I want it to print out in the GUI window without all the {[( and extra spaces...
It prints out at the command line ok, but the GUI is not-so clear.

Thanks for any help.

``````######################################
def compare ():

s=''
comp_a = open("C:\output.txt","r")
s = [line.split() for line in s.strip().splitlines()]
target = drawing2.split()
print('Purchased Numbers are',s)
print('Win Number is ',target)

def score(a, b):

return (len(set(a[:5]) & set(b[:5])), 1 if (a[-1] == b[-1]) else 0)
print()

for a in s:
print(a, score(a, target))
label1 = Label(aApp,text =("Results  [                      ] ",(a, score(a,target))),fg = 'blue')
comp_a.close()

#################################
The program
#################################

from tkinter import*
import sys, random, tkinter
ticket_price = 2
i=0
g=''
total  = 0
comp_a=' '
comp_b=' '
score=0
drawing2=''
drawing=''
target=''
s=''
sx=' '
a=''
b=''
test_score = ''

def calculatetotals():
valid = set('12345')
ticket_entry = tik.get()
if ticket_entry not in valid:
print('We permit values in {}.'.format(valid))
label4 = Label(aApp,text = 'We permit values in 1, 2, 3, 4 or 5!',fg = 'blue').grid(row=7,column=1)
else:
label4 = Label(aApp,text = '                                                                        ',fg = 'blue').grid(row=7,column=1)
mytik=int(ticket_entry)
total = mytik*ticket_price
Label(aApp,text= "You purchased:\$%.2f \n" %  total).grid(row=7,column=1)
Label(aApp,text= "\nNumber Of Tckets: %.f\n" % mytik).grid(row=6,column=1)
,command = nextx).grid(row=8,column=1)

aApp=Tk()
aApp.geometry('600x400+75+75')
aApp.title("LOTTO")

tik=StringVar()
label1 = Label(aApp,text = "Welcome To Lotto.",fg = 'blue')
label1.grid(row=0,column=2)
label2=Label(aApp,text="Tickets Are \${:.2f} Each.".format(ticket_price),fg='red')
label2.grid(row=1,column=1)
label3=Label(aApp,text="How Many Would You Like?",fg='black')
label3.grid(row=2,column=1)
mytik = Entry(aApp,textvariable=tik)
mytik.grid(row=2,column=2)
,command=calculatetotals)
button1.grid(row=6,column=1)

def nextx():
,command = nextz).grid(row=8,column=1)
ticket_entry = tik.get()
i = 0

while i < int(ticket_entry):
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
drawing = ' '.join( [' '.join (zstr(G) for G in g),'-',zstr(f[0])])
label5=tkinter.Label(aApp,text = drawing)
label5.pack(fill=X)

comp_b = open("C:\output.txt","a")
s = comp_b.write(drawing)
s=comp_b.write('\n')
s = [line.split() for line in sx.strip().splitlines()]
i+=1

def  nextz():
Button(aApp,text='Push   again to  <Quit> : To see if you match Push <Compare> In The New Winning Number Window, '\
,fg='yellow',bg='black',command = quit).grid(row=8,column=1)
L = list(range(1,60))
random.shuffle(L)
g = L[:5]
g.sort()
f = L[5:6]
global drawing2
global target
drawing2 = ' '.join( [' '.join (zstr(G) for G in g),'-',zstr(f[0])])
target=drawing2
aBpp=tkinter.Tk()
aBpp.geometry('240x75+230+260')
aBpp.title(string="Winning Number")
Button(aBpp, text="quit", command=aBpp.quit).pack()
Button(aBpp, text="Compare", command=compare).pack()

def zstr(ob, width = 2):
return '{x:0>{width}s}'.format(x = str(ob), width = width)

def compare ():

s=''
comp_a = open("C:\output.txt","r")
s = [line.split() for line in s.strip().splitlines()]
target = drawing2.split()
print('Purchased Numbers are',s)
print('Win Number is ',target)

def score(a, b):

return (len(set(a[:5]) & set(b[:5])), 1 if (a[-1] == b[-1]) else 0)
print()

for a in s:
print(a, score(a, target))
label1 = Label(aApp,text =("Results  [                      ] ",(a, score(a,target))),fg = 'blue')
comp_a.close()

killfile = open("C:\output.txt","w")
killfile.close()

tkinter.mainloop()
app.mainloop()
aApp.mainloop()
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.