#!/usr/bin/env python3 import random from time import monotonic def main(): aufgabenanzahl = int(input("Wie viele Durchgänge? ")) punkte = 0 total_time = 0 for _ in range(aufgabenanzahl): operanden = [random.randint(1, 10) for _ in range(4)] start_time = monotonic() antwort = int( input("Wieviel ist {} * {} + {} - {}? ".format(*operanden)) ) elapsed_time = monotonic() - start_time total_time += elapsed_time loesung = operanden[0] * operanden[1] + operanden[2] - operanden[3] if antwort != loesung: print(f"Falsch! Richtig ist {loesung}.") else: print(f"Richtig! {elapsed_time:.2f} Sekunden") punkte += 1 print( f"{punkte} Punkte! Du hast {punkte} von {aufgabenanzahl} Aufgaben" f" richtig gerechnet!" ) print(f"Das sind {punkte / aufgabenanzahl:.0%}!") print(f"Gesamtzeit für {aufgabenanzahl} Aufgaben: {total_time:.2f}s") if __name__ == "__main__": main()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter