Skip to content

Instantly share code, notes, and snippets.

@ryo-murai
Created December 24, 2018 00:12
Show Gist options
  • Save ryo-murai/e56e2aaf3765a48e24d5de8b9cbe9ef3 to your computer and use it in GitHub Desktop.
Save ryo-murai/e56e2aaf3765a48e24d5de8b9cbe9ef3 to your computer and use it in GitHub Desktop.
足し算
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