0

exercices (to hard for 7year old)

Hi, guys, how can I make sure these exercices never have an negative (below zero) or float outcome? I'm making this for my kid, who does not understand the negative or decimal number. import random def minus(): x= random.randrange(10) y= random.randrange(10) result= x-y print((x), '-', (y), '=', result) def div(): x = random.randrange(1,10) y = random.randrange(1,10) result= x/y print((x), '/', (y), '=', result) minus() div() //examples (like wich I don't want anymore): 3 - 8 = -5 4 / 3 = 1.3333333333333333

30th Mar 2020, 6:42 PM
T D
T D - avatar
4 odpowiedzi
+ 4
begin with result and get a random number n result+n - n result*n / n
30th Mar 2020, 7:28 PM
Oma Falk
Oma Falk - avatar
+ 3
This should work: def minus(): x= random.randrange(10) y= random.randrange(x+1) result= x-y print((x), '-', (y), '=', result) def div(): x = random.randrange(1,10) y = random.randrange(1,10) while x%y: y = random.randrange(1,10) result= x//y print((x), '/', (y), '=', result)
30th Mar 2020, 7:03 PM
HonFu
HonFu - avatar
+ 2
import random def minus(): x = random.randrange(10) y = random.randrange(10) if x < y: x, y = y, x result = x - y print(x, '-', y, '=', result) def div(): result = random.randrange(1,4) y = random.randrange(1,4) x = result * y print(x, '/', y, '=', result) minus() div()
30th Mar 2020, 7:01 PM
andriy kan
andriy kan - avatar