所以我正在寫一個輸入3#數字並將其分開的程序。我無法弄清楚如何添加單獨的數字?加上三位數字的總和
例如:用戶輸入345
我的計劃將打散的#'s到3,4,5但我怎麼再添加這些數字加在一起?
這是我的代碼迄今,
#set variable
val = raw_input("Type your three digit number please: ")
print 'The first digit is {}'.format(val[0])
print 'The second digit is {}'.format(val[1])
print 'The third digit is {}'.format(val[2])
#set variable
total = [val[0] +val [1] + val[2]]
total_value = total
print 'The sum of the three digits is' total_value
閱讀[我的回答(http://stackoverflow.com/a/15566019/939986)到您的[前一個問題(http://stackoverflow.com/q/15565656/939986)仔細。 – 2013-03-22 09:59:28
@SantoshKumar確實!爲什麼相同的問題兩次?聽起來像絕望,做一些功課。 :D – ecline6 2013-03-22 15:17:01