python - 我必须修改错误的代码。但是我卡在下面的部分,我在 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 将不会执行。当你写:
a = "Hello" + 2
无法确定是要将“Hello”的数值加上2还是将2的字符串值加上“Hello”
为了解决这个问题,您只需要得出结论,在这种情况下:
a = "Hello" + str(2)
这将导致 python 将 2 个字符串添加在一起以获得“Hello2”
推荐阅读
- arrays - 角垫列表垫列表项数组
- ios - 使用 AVAudioSession 快速检测其他音频的属性
- c - 解析 C 中的字符串,无需 Stok()
- vb.net - SSIS 脚本任务抑制 onerror
- flutter - 如何实现 ViewPage onTouch?
- python - string.isalpha() 在自定义 django 验证器下返回 False,无论字符串是否包含数字
- robotframework - RobotFrameWork:如何从一个页面获取文本并在另一个页面中输入文本?
- c# - 如何在 C# 中连接到 RavenHQ
- salesforce - 为什么我不能有两种页面格式到一个记录类型?
- python - ImportError:无法在虚拟环境中导入名称 main