Created
August 3, 2021 01:50
-
-
Save maurobaraldi/7d9206aac5609b2895474c73a4e7b468 to your computer and use it in GitHub Desktop.
Exercícios com números naturais
This file contains 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
from random import randint, choice | |
def plus_minus_expressions(quantity: int = 30) -> None: | |
for i in range(quantity): | |
n = lambda: choice([1,-1])*randint(0, 10) | |
oper = choice(['-', '+']) | |
print(f'{n()} {oper} {n()} {oper} {n()} = ') | |
def division_times_expressions(quantity: int = 30) -> None: | |
for i in range(quantity): | |
n = lambda: choice([1,-1])*randint(0, 10) | |
oper = choice(['*', ':']) | |
a, b = n(), n() | |
if b == 0: | |
b += 1 | |
if oper == ':' and (a%b != 0): | |
a = b * a | |
print(f'{a} {oper} {b} = ') | |
plus_minus_expressions() | |
division_times_expressions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment