mconfigQuantity = int(raw_input('Enter the number of (m)achine-configurations that you will need: '))
numberOfmconfig = 1
for mconfigs in range(1,mconfigQuantity+1):
# %s conditional for mcidentifier
STRINGnumberOfmconfig = str(numberOfmconfig)
if STRINGnumberOfmconfig[-1] == '1':
suffix = 'st'
elif STRINGnumberOfmconfig[-1] == '2':
suffix = 'nd'
elif STRINGnumberOfmconfig[-1] == '3':
suffix = 'rd'
else: suffix = 'th'
finalConfigName = STRINGnumberOfmconfig + suffix
mcidentifier = raw_input('Enter the letter of your %s (m)achine-configuration: ') % (finalConfigName)
numberOfmconfig = numberOfmconfig + 1
print mconfig()
我已经编写并重写了几次这个片段,对于我为什么打印'%s'而不是用我为其指定的数据替换它是没有意义的。我找不到任何表明它无法正常工作的东西。
答案 0 :(得分:5)
应该是
mcidentifier = raw_input(
'Enter the letter of your %s (m)achine-configuration: ' % finalConfigName)
您在%
运算符之前关闭了括号,因此将其应用于结果字符串,即raw_input
返回的字符串。
另请注意,在新代码中,建议使用新的字符串格式化语法:
mcidentifier = raw_input(
'Enter the letter of your {} (m)achine-configuration: '.format(finalConfigName))