Skip to content
Snippets Groups Projects
Commit 0c21f5b0 authored by Pinja Kiviahde's avatar Pinja Kiviahde
Browse files

Upload New File

parent bf9ac0d8
No related branches found
No related tags found
No related merge requests found
import re
from operator import add, sub, mul, truediv
print("Luku on 0.")
lista =[]
def laske(lista):
ops = {'+': add, '-': sub, '*': mul, '/': truediv}
result = 0
for x in lista:
op, num = re.match(r'([+\-\*/])(\d+)', x).groups()
result = ops[op](result, int(num))
return result
while True:
luku = input("Anna operaatio (tyhjä lopettaa): ")
if luku == "":
break
lista.append(luku)
print(f"Luku on {int(laske(lista))}.")
print("Kiitos ja moi!")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment