Python 不支持的操作数所有数学符号和浮点?
我的主要错误是 TypeError:/:“str”和“int”的操作数类型不受支持Python 不支持的操作数所有数学符号和浮点?,python,geany,Python,Geany,我的主要错误是 TypeError:/:“str”和“int”的操作数类型不受支持 #Name variables/imports. Ask usr for scale lengh and num of frets import math scalelenth = input ("please inter a number for scale \n > " ) constnum = 17.817 #Calculate Fret one distance fretum = scale
#Name variables/imports. Ask usr for scale lengh and num of frets
import math
scalelenth = input ("please inter a number for scale \n > " )
constnum = 17.817
#Calculate Fret one distance
fretum = scalelenth / constnum
print("this is scale lenth %d " %scalelenth)
在Python3中,input()
返回一个字符串。您需要将其转换为数字:
scalelenth = int(input("Please enter a number for scale \n > "))
如果要包含小数,请使用float()
:
在Python3中,input()
返回一个字符串。您需要将其转换为数字:
scalelenth = int(input("Please enter a number for scale \n > "))
如果要包含小数,请使用float()
:
您需要先将字符串转换为浮点,然后进行计算:
fretum = float(scalelenth) / constnum
您需要先将字符串转换为浮点,然后进行计算:
fretum = float(scalelenth) / constnum
scalelength
是一个字符串(假设您使用的是python3.x),而str*float
不起作用(它会做什么?)
修复方法是将字符串转换为浮点:
fretum = float(scalelength)/ constnum
scalelength
是一个字符串(假设您使用的是python3.x),而str*float
不起作用(它会做什么?)
修复方法是将字符串转换为浮点:
fretum = float(scalelength)/ constnum
我点击了“代码”按钮,但它不起作用。我如何编辑以找出我做错了什么?没有编辑按钮吗?我想你需要这样做:
float(输入(…)
谢谢你,非常感谢你的快速回复。它现在可以工作了。我点击了“代码”按钮,但它没有工作。我如何编辑以找出我做错了什么?没有编辑按钮吗?我想你需要这样做:float(输入(…)
谢谢你,非常感谢你的快速回复。现在可以了。