Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 174
#Some basic arithmetic with hints and dynamic feedback:: %auto %exercise k = randint(2,5) title = "Add %s numbers"%k v = [randint(1,10) for _ in range(k)] question = "What is the sum $%s$?"%(' + '.join([str(x) for x in v])) answer = sum(v) hints = ['This is basic arithmetic.', 'The sum is near %s.'%(answer+randint(1,5)), "The answer is %s."%answer] def check(attempt): c = Integer(attempt) - answer if c == 0: return True if abs(c) >= 10: return False, "Gees -- not even close!" if c < 0: return False, "too low" if c > 0: return False, "too high"
Interact: please open in CoCalc