3 回答
TA贡献1833条经验 获得超4个赞
我正在尝试制作一个非常简单的 Python 程序,它将美元转换为几种不同的货币。我在使用 IF/ELIF 语句时遇到问题。每当我在我的解释器中运行代码时,在这种情况下是 Pycharm,解释器会提示我输入我想转换的值,然后是我想转换的货币,然后完成而不打印我设置的任何内容IF/ELIF 语句。
代码:
import os
os.system('cls')
# This code starts the program and explains
# the purpose of the program to the user.
print()
print("Hello User")
print("This program will convert dollars to yen.")
print()
# This code prompts the user to enter a dollar amount.
USD = input("Amount of dollars: ")
# This code converts the user entered amount as a floating
# point integer for ease of calculation and error correcting.
var1 = float(USD)
print("YEN: 1")
print("EUR: 2")
print("RUB: 3")
print("Yuan: 4")
var2 = input("What Currency Do You Want To Convert To?: ")
def my_converter():
if var2 == 1:
var3 = var1 * float(114.62)
var4 = "Yen"
print(USD, "U.S. Dollars equals", var3, var4)
elif var2 == 2:
var3 = var1 * float(1.14)
var4 = "Euro"
print(USD, "U.S. Dollars equals", var3, var4)
elif var2 == 3:
var3 = var1 * float(0.015)
var4 = "Rubles"
print(USD, "U.S. Dollars equals", var3, var4)
elif var2 == 4:
var3 = var1 * float(0.15)
var4 = "Yuan"
print(USD, "U.S. Dollars equals", var3, var4)
我刚刚开始使用 Python,所以我可能只是遗漏了一些非常明显的东西,但任何帮助将不胜感激。如果这是一个重复或愚蠢的问题,我们深表歉意。
添加回答
举报