我得到的主要错误是;
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)
答案 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