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
4 odpowiedzi
+ 4
begin with result
and get a random number n
result+n - n
result*n / n
+ 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)
+ 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()