不支持的操作数所有数学符号和浮点数?

时间:2016-03-01 04:20:11

标签: 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 = scalelenth / constnum 

print("this is scale lenth %d " %scalelenth)

3 个答案:

答案 0 :(得分:0)

在Python3中,input()返回一个字符串。您需要将其转换为数字:

scalelenth = int(input("Please enter a number for scale \n > "))

如果要包含小数,请使用float()

scalelenth = float(input("Please enter a number for scale \n > "))

答案 1 :(得分:0)

首先需要将字符串转换为float,然后进行计算:

fretum = float(scalelenth) / constnum 

答案 2 :(得分:0)

scalelength是一个字符串(假设您使用的是python3.x)并且str * float不起作用(它会做什么?)

修复方法是将字符串转换为float:

fretum = float(scalelength)/ constnum