为什么这个功能有效?我不明白

问题描述 投票:0回答:1
modeRead = ("1","0")
print("Hello! Welcome to Business Dynamics! You are currently in the calculation area. V1.0.0")


f1 = int(input("input first number "))
o = input("input operator eg. * / - + ")
s1 = int(input("input second number "))

if o == "*":
  print(f"number = {f1 * s1}")
elif o == "+":
  print(f"number = {f1 + s1}")
elif o == "-":
  print(f"number = {f1 - s1}")
elif o == "/":
  print(f"number = {f1 / s1}")

changeConvert = input("if you wish to change to convert mode, input CONVERT.")

if changeConvert == "CONVERT":
  print("You are now in convert mode.")
  
elif changeConvert == "":
  print("Oops! Please run this again.")

calcArea = modeRead = 0
convArea = modeRead = 1
modeAsk = input("say mode")
if modeAsk == "mode":
  print(modeRead)

这就是我的项目。这是一个商业数据计算器,这是我的第一个Python领域。正如您所看到的, convArea 和其余部分之间没有任何连接。但是当我运行代码时,它似乎......工作?事实上,没有它它就无法工作。 我换了号码,还能用吗?我不知道。

python
1个回答
0
投票

不知道你的意思,但你写的代码是有效的,因为它有效。没有语法错误或注释掉的代码,因此当您编写代码然后运行它时,该代码就会运行。

我实际上对Python了解不多,但似乎

convArea
,你刚刚定义了一个变量。在编程中,有时您通常可以在不使用关键字或 JavaScript 中的类似内容的情况下定义变量:“var coin = 20;”,而是像“coins = 20;”那样定义变量。

© www.soinside.com 2019 - 2024. All rights reserved.