-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfin_world.py
More file actions
130 lines (82 loc) · 3.48 KB
/
fin_world.py
File metadata and controls
130 lines (82 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#****************************************************************
# caps quiz - d.e.Howe kingston ont. 2017 October
# quiz logic when finished may offer mult. lists to quiz with
#****************************************************************
from tkinter import *
import random
import copy
import csv # getting my lists from csv files so I do not need to store data in script
with open('world_caps.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
countrys = []
capitals = []
for row in readCSV:
country = row[0]
capital = row[1]
countrys.append(country)
capitals.append(capital)
# print(countrys)
# print(capitals)
#print(len(countrys))
#print(len(capitals))
# getting my lists from csv files so I do not need to store data in script
short_list = ['1','2','3','4','5'] # not sure i need the dummy fields?
score = 0
count = 0
cap = copy.copy(capitals)
new_list = copy.copy(capitals)
states = copy.copy(countrys)
#****************************************************************
# caps quiz - d.e.Howe kingston ont. 2017 October
# function ShowChoice
# START
#****************************************************************
def ShowChoice():
global count
global score
x = v.get()
if x == cap[count]:
score = score + 1
count = count + 1
root.destroy()
#****************************************************************
# caps quiz - d.e.Howe kingston ont. 2017 October
# function ShowChoice
# END
#****************************************************************
while count < 197:
#****************************************************************
# caps quiz - d.e.Howe kingston ont. 2017 October
# shuffle my newlist a copy of the original cap[] list
# then pull the top five from the list that are now random
# these are now my choices for the user - since i want to insert the correct answer
# I need to be sure it is not already in the random list i check and if it is
# I replace it with next off shuffled list so I can then insert the correct answer at random
#****************************************************************
random.shuffle(new_list)
for i in range(5):
short_list[i] = new_list[i]
for i in range(5):
if short_list[i] == cap[count]:
short_list[i] = new_list[5]
from random import randint
r = randint(0, 4)
short_list[r] = cap[count]
root = Tk()
root.geometry("500x500+290+90")
Label(root,text="\nThe Capital of " + states[count] + " is?\n", font=18).grid(row=2,column=0)
v = StringVar()
for i in range(5):
b = Radiobutton(root, text =short_list[i], variable=v,command=ShowChoice, value=short_list[i],font=18,indicatoron=0)
b.grid(row= i+4,column=1, sticky=W)
gif_one = Text(root,height=8, width=25)
photo=PhotoImage(file='./unflag.png')
gif_one.image_create(END, image=photo)
gif_one.grid(row=10,column=0)
Label(root,text=' Score = '+ str(score),font=24).grid(row=10,column=2,sticky=W)
Label(root,text='\n You have: ' + str(score) + ' of ' + str(count) + ' correct.\n\n',font=24).grid(row=12,column=0,sticky=W)
if count > 0:
Label(root,text=' or: ' + str(int(100 * score/count)) + ' Percent',font=24).grid(row=12,column=1,sticky=W)
done = Button(root,text =' QUIT ',command=quit).grid(row=16,column=1)
root.bind('<Return>',ShowChoice)
mainloop()