Первые шаги а написание кода, подскажите как зациклить калькулятор?
# Дебильный калькулятор V.2.0
from colorama import init
from colorama import Fore, Back, Style
# use Colorama to make Termcolor work on Windows too
init()
print( Fore.BLACK )
print( Back.YELLOW )
what = input( "Selected action (+, -, *, **, %, /): " )
print( Back.GREEN )
a = float( input("Enter a first number: ") )
print( Back.CYAN )
b = float( input("Enter a second number: ") )
print( Back.MAGENTA )
if what == "+":
c = a + b
print ("Result: " + str(c))
elif what == "*":
c = a * b
print ("Result: " + str(c))
elif what == "**":
c = a ** b
print ("Result: " + str(c))
elif what == "%":
c = a % b
print ("Result: " + str(c))
elif what == "/":
c = a / b
print ("Result: " + str(c))
elif what == "-":
c = a - b
print ("Result: " + str(c))
else:
print( Back.RED )
print("Error 404")
Ответы (1 шт):
Автор решения: YanaC
→ Ссылка
Бесконечный цикл
while True: кодКонечное число операций
i = 0 while i < 100: код i += 1
или
i = 0
iterations = 100
while i < iterations:
код
i += 1
или
for _ in range(iterations):
код
путем ввода команды, завершающей цикл, например "stop"
while True: what = input( "Selected action (+, -, *, **, %, /): " ) if what == 'stop': break else: ваш код