Answer the question
In order to leave comments, you need to log in
How to build a loop in python without error?
Please tell me how to make a loop in a simple python program.
usd = 65.59
euro = 75.37
new_exchange = []
money = int (input("Введите сумму, которую хотите обменять в валюту "))
exchange = input ("Выберите валюту (USD или Euro) ")
while new_exchange == ():
if exchange.lower() == "usd":
result_usd = money * usd
print("После обмена вы получите", result_usd, "долларов сша")
elif exchange.lower() == "euro":
result_euro = money * euro
print("После обмена вы получите", result_euro, " евро")
new_exchange = input ("Хотите снова обменять?? ")
if new_exchange.lower == "да"
print("Работа программы завершена! ")
File "C:\python\test.py", line 17
result_usd = money * usd
^
IndentationError: expected an indented block
usd = 65.59
euro = 75.37
money = int (input("Введите сумму, которую хотите обменять в валюту "))
exchange = input ("Выберите валюту (USD или Euro) ")
if exchange.lower() == "usd":
result_usd = money * usd
print("После обмена вы получите", result_usd, "долларов сша")
elif exchange.lower() == "euro":
result_euro = money * euro
print("После обмена вы получите", result_euro, " евро")
print("Работа программы завершена! ")
Введите сумму, которую хотите обменять в валюту 4
Выберите валюту (USD или Euro) euro
После обмена вы получите 301.48 евро
Работа программы завершена!
Answer the question
In order to leave comments, you need to log in
In this program, you don’t count how many dollars or euros you get, you count the other way around - how many rubles you get for N currencies
. Since you need the program to work, it will work with this code
usd = 0.01524622655
euro = 0.01326787846
def exchng():
money = int(input("Введите сумму, которую хотите обменять в валюту "))
exchange = input("Выберите валюту (USD или Euro) ")
if exchange.lower() == "usd":
result_usd = money * usd
print("После обмена вы получите", result_usd, "долларов сша")
elif exchange.lower() == "euro":
result_euro = money * euro
print("После обмена вы получите", result_euro, " евро")
new_exchange = 1
while new_exchange == 1:
exchng()
rep = input("Хотите снова обменять?? (Y/N) ")
if(rep.upper() == "N"):
print("Работа программы завершена! ")
new_exchange = 0
break
Error in indents (You need to add indents after ifs in your loop).
Python is case and indentation sensitive. - This is his main feature!
One indent is 4 spaces or one tab, if you use it this way and that, it will also be an error!
PS I know that I'm not the first to answer but I decided to answer!
IndentationError: expected an indented block <- indentation error. Python is case and indentation sensitive. Blocks must be indented, by default 4 spaces. Do not use tabs:
x = 5
if x == 10:
print('x == 10')
elif x == 3:
print('x == 3')
else:
print('x что-то странное')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question