【问题标题】:If statements using a checkbox in HTML/Javascript [duplicate]如果在 HTML/Javascript 中使用复选框的语句 [重复]
【发布时间】:2018-04-16 11:07:31
【问题描述】:

我试图找到变量 x 和变量 y 的值,但我无法正确划分它。我总是收到涉及 z 变量的错误。

x = str(input("What was your total: "))
y = str(input("What percentage of a tip would you like to give (15 or 20): "))
z = float(x / y)

print("The tip you will want to give will be: " + z)

input("\n\nPress the enter key to exit")

【问题讨论】:

  • xy 是字符串。你不能把它们分开。
  • z = float(x / y) TypeError: unsupported operand type(s) for /: 'str' and 'str'

标签: python


【解决方案1】:

修正版:

x = int(str(input("What was your total: ")))
y = int(str(input("What percentage of a tip would you like to give (15 or 20): ")))
z = float(x / y)

print("The tip you will want to give will be:", z)

input("\n\nPress the enter key to exit")

【讨论】:

  • 当然,(x / y) 是错误的公式...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-04
  • 2018-05-13
  • 2022-01-17
  • 2019-12-19
  • 2013-10-06
  • 2012-01-12
  • 2015-09-30
相关资源
最近更新 更多