2013-12-08 140 views
0

使用Python字符串格式化格式化與運營商的錯誤,我的預期成果是:字符串在python

If you took 19 and 13 and added them, you would get 22 

但不是很確定如果我有得當的。我一直得到這個錯誤:

Not all arguments converted during string formatting 

你能幫忙嗎?

代碼:

my_age = 19 
teenager = 13 

print "If you took %s and %s and added them, then you will get %" %(my_age,teenager,my_age + teenager) 
+0

你最後'%後失蹤的說明符'。您需要:'「get%d」' –

回答

1

你只是缺少最後%後,最後的'字符串

print "If you took %s and %s and added them, then you will get %s" %(my_age,teenager,my_age + teenager) 
+0

Aaah正確,謝謝。 – TKA

+0

@TKA如果你得到了你想要的答案,不要忘了點擊複選標記。如果答案有幫助但不完全正確,那麼贊成OP就很有禮貌。 –