Skip to content

Instantly share code, notes, and snippets.

@maurobaraldi
Created August 3, 2021 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurobaraldi/7d9206aac5609b2895474c73a4e7b468 to your computer and use it in GitHub Desktop.
Save maurobaraldi/7d9206aac5609b2895474c73a4e7b468 to your computer and use it in GitHub Desktop.
Exercícios com números naturais
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