我需要计算更粗糙的指数,但我遇到了这个问题。我该怎么修?
def ruffier_index(P1, P2, P3): global index intermediate = 4*(P1+P2+P3) index = (intermediate-200)/10 return index
bpm = TextInput(multiline = False, size_hint=(None, None), width = 100, height = 30, pos_hint = {'center_x' : 0.4, 'center_y' : 0.3}, input_filter = 'int') self.bpm1 = bpm.text
我将此变量转换为int,但遇到了另一个问题
self.bpm1 = bpm.text
invalid literal for int() with base 10: ''
您正试图将空字符串转换为整数,这是不可能的。发生这种情况是因为 bpm.text 属性为空,直到用户在 TextInput 小装置。要解决此问题,您需要检查 bpm.text 属性在转换为整数之前不为空。例如,您可以像这样使用try-except块:
bpm.text
TextInput
try: self.bpm1 = int(bpm.text) except ValueError: # Handle the case when bpm.text is empty or not a valid integer print("Please enter a valid integer for bpm")