I have this code for a "quiz" type of program for periodic table. What i need help with is how can make it to pick a random symbol from the class and ask for its atom number and check if the answer is correct number for the symbol.
The way i got symbols and weight are from a file and the atomnumber is from the fucntion "listor_1" and I started it as number = 0 and the rest can be seen by the code how i then get it and store it in class, as the number does not get included in the file.
Heading
class Grund_element(object):
def __init__(self, atomsymbol, atomweight, atomnumber):
self.__atom_symbol = atomsymbol
self.__atom_weight = atomweight
self.__atom_number = atomnumber
def symbol1(self):
return self.__atom_symbol
def weight1(self):
return self.__atom_weight
def number1(self):
return self.__atom_number
def listor_1(elem_list):
elementer = []
number= 0
for i in range(0, len(elem_list), 2):
number+=1 #adding by 1 to get atomnumber for each symbol
element = Grund_element(elem_list[i], elem_list[i + 1], number)
elementer.append(element)
return elementer
def antal_test(ordlista):
svarlista = []
for element in range(len(ordlista)):
resultat_lista = check_answ(ordlista[element].symbol1(),
ordlista[element].weight1(), ordlista[element].number1())
svarlista.append(resultat_lista)
def check_answ(symbol, weight, number):
lista=""
life=3
answer=None
while (svar != str(number) and life>0):
answer= input(str(" Which number does " +symbol+ have "?:
"+str(life)+" life left. \n"))
life-=1
if (answer== str(number)):
print("Correct. \n")
else:
print("wrong, right answer: "+str(number)+". \n")
Aucun commentaire:
Enregistrer un commentaire