Created
December 24, 2018 00:12
-
-
Save ryo-murai/e56e2aaf3765a48e24d5de8b9cbe9ef3 to your computer and use it in GitHub Desktop.
足し算
This file contains hidden or 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
def question(a, b, nWrong = 0): | |
s = input("%d + %d = " % (a, b)) | |
if int(s) == a + b: | |
print("正解") | |
return True | |
else: | |
print("ちがいます") | |
if nWrong < 2: | |
print("もう一度") | |
return question(a, b, nWrong + 1) | |
else: | |
print("正解は%dでした。次の問題" % (a+b)) | |
return False | |
if __name__ == "__main__": | |
pairs = [ | |
(1,2), | |
(4,2), | |
(12378964,4895743052), | |
(4389,4398), | |
(512,256) | |
] | |
corrects = [question(a,b) for a,b in pairs].count(True) | |
print("%d問中 %d問正解でした" % (len(pairs), corrects)) | |
print("お疲れ様でした") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment