Last active
February 3, 2021 14:15
-
-
Save Quiri/2f5151b462f3b7ac360bb099a8cb6138 to your computer and use it in GitHub Desktop.
Mathe bis 20 üben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Den ganzen Code bei R ausfüllen | |
## Optional das Feedback personalisieren | |
## Eingabe von x beendet das Programm | |
gut <- c("Toll!", "Super!", "Nice!", "Умница!", "Mathegenie!") | |
nein <- c("Leider falsch", "Versuch's nochmal", "Du hast es gleich!") | |
x <- "q" | |
while(TRUE){ | |
if(x == "x") { | |
break() | |
} | |
a <- ceiling(runif(1,0,20)) | |
b <- ceiling(runif(1,0,20)) | |
if (runif(1) < 0.5) { | |
while(a+b > 20) { | |
a <- ceiling(runif(1,0,20)) | |
b <- ceiling(runif(1,0,20)) | |
} | |
if(a+b > 20){ | |
a = a -10 | |
} | |
cat(a, "+", b, "=") | |
falsch <- TRUE | |
while(falsch) { | |
x <- readline() | |
if(x == "x"){ | |
break() | |
} | |
falsch <- a+b != x | |
if(falsch) { | |
cat(sample(nein, 1), "\n") | |
} else { | |
cat(sample(gut, 1), "\n\n") | |
} | |
} | |
} else {#minus | |
if (a < b) { | |
temp <- a | |
a <- b | |
b <- temp | |
} | |
cat(a, "-", b, "=") | |
falsch <- TRUE | |
while(falsch) { | |
x <- readline() | |
if(x == "x"){ | |
break() | |
} | |
falsch <- a-b != x | |
if(falsch) { | |
cat(sample(nein, 1), "\n") | |
} else { | |
cat(sample(gut, 1), "\n\n") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment