首页 > 解决方案 > 我必须修改错误的代码。但是我卡在下面的部分,我在 python 中遇到了这个错误

问题描述

#this is a program to run on the HY92 module for the Nanya Rocket
print ("Program initiating")
date_today = "16 December 2016"
print (date_today)
print ('Mission Launch ' + 'Procedure 14.0')
module_name = "string(HY92)"
#the following are numerical variables
A1 = 4
A2 = 28
A3 = 10 #this is a module identifier
A4 = 14 #this is another module identifier
A5 = 39 
A6 = 6
#this is a section which uses the variables defined above
product = (A1 * A2)
quotient = (A4 / A3)
module_math = (product + quotient)
Clearance_Given = true
Clearance_Status = Clearance_given + module_math + module_name
sleep_time = 1
#print 'Program closing in...'
sleep(sleep_time)
print (5)
sleep(sleep_Time)
print (4)
sleep(sleep_time)
print (3)
sleep(sleep_time)
print (3)
sleep(sleep_time)
print (1)
sleep(sleep_time) 
print ("closed")

我做了很多修复,但是我卡在第 19 行显示的错误上,告诉我我只能将 str (不是 float )连接到 str

标签: python

解决方案


如果行不明确,Python 将不会执行。当你写:

a = "Hello" + 2

无法确定是要将“Hello”的数值加上2还是将2的字符串值加上“Hello”

为了解决这个问题,您只需要得出结论,在这种情况下:

a = "Hello" + str(2)

这将导致 python 将 2 个字符串添加在一起以获得“Hello2”


推荐阅读