@Littlejofel
Du beginnst, Variablen zu nummerien (`frage1` ...). Stell' Dir einmal vor, Dein Quiz nimmt 'Trivial Pursuit' Dimensionen an...

. Zudem ist das Feature, mehrere Antworten zu geben, sehr fehlerbehaftet, was ist z. B., wenn der Spieler '1, 2' oder '12' eingibt?
Ich habe Dir mal ein kleines Beispiel notiert, das zumindest diese Dinge umschifft:
Code: Alles auswählen
import re
tasks = (
{'question': 'Was versteht man unter Software?',
'choices': ('1) Dateien',
'2) Ausfuehrbare Programme',
'3) Computerbauteile'),
'solutions': ('2',)},
{'question': 'Welches gehoert zu meinen Leibgerichten?',
'choices': ('1) Zwiebelrostbraten mit Kaesspatzn',
'2) Pizza Classico mit Kaese im Rand',
'3) McRib mit extra Westernsauce'),
'solutions': ('1', '2', '3')}
)
def get_answers():
return re.findall(r'(\d)', raw_input())
def validate_answers(answers, solutions, fully):
'''`fully` = True: All answers must be correct
`fully` = False: At least one answer must be correct '''
results = [answer in solutions for answer in answers]
if fully:
return all(results) and sum(results) == len(solutions)
return any(results)
def run():
print 'Willkommen zum Quiz'
print '___________________'
for number, task in enumerate(tasks):
print '\nHier die {}. Frage:'.format(number+1)
print task['question']
print '\n'.join(task['choices'])
answers = get_answers()
if validate_answers(answers, task['solutions'], fully=True):
print 'Ja, ganz genau!'
else:
print 'Leider nicht'
if __name__ == '__main__':
run()
mutetella