小编use*_*867的帖子

编写一个接受两位数#的程序,将其分解

我目前正在使用Python创建一个程序,接受两位数字的用户输入,并将输出数字在一行.

例如:我的程序将从用户处获得一个号码,让我们只使用27

我希望我的程序能够打印"第一个数字是2"和"第二个数字是7"我知道我将不得不使用模块(%)但我是新手,有点困惑!

python

5
推荐指数
1
解决办法
159
查看次数

添加三位数的总和

所以我正在编写一个输入3#数字并将其分开的程序.我无法弄清楚如何完全添加单独的数字?

例如:用户输入345

我的程序会将#分开为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
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
4466
查看次数

标签 统计

python ×2