Ich bin nur ein Anfänger zu python.Und ich habe hier nur ein einfaches Programm geschrieben, nur um mich selbst zu bewerten und versuchen, die Fragen in zufälliger Reihenfolge zu beantworten. Aber der Fehler hier ist, dass der Randint Funktion erwirbt manchmal die gleiche Nummer, die bereits erworben wurde, dass ich die gleiche Frage wiederholt bekomme. Ich versuchte mein Bestes, um es zu beheben, aber ich konnte nicht. Hoffe, dass ich etwas Hilfe bekommen here.`import zufälligePython-randint Funktion ohne Wiederholung
global some
global i
i=0
some=[]
names=['electric charge','permitivity of the medium','permitiovity of free space','relative permitivity of the medium','intensity of the electric field','electric potential at a point','electric potential energy','dipole moment','torque acting on the dipole','electric flux','linear charge density of the conductor','surface charge density of the conductor','capacitance of a parallel plate capacitor','practical unit of capacitance']
answer=['C','C2N-1m-2','C2N-1m-2','no unit','NC-1 or Vm-1','V','J','Cm','Nm','Nm2C-1','Cm-1','Cm-2','F','uF or pF']
def loop(i):
for i in range(i,len(names)):
global qno
qno=random.randint(0,len(names))
if i>0:
for k in range(0,len(some)):
if str(qno)==some[len(some)-1]:
loop(i-1)
print(names[qno])
print('Type your answer')
tell=input()
if tell==answer[qno]:
print('Right answer.Move on')
else:
print('Wrong answer,.The answer is '+answer[qno])
for j in range(i+1):
some.append(str(qno))
i=i+1
loop(i)
`
benutze 'random.shuffle (list)' und du bekommst eine Liste mit zufälliger Reihenfolge - und dann kannst du Elemente mit 'for' loop bekommen. – furas