小编use*_*405的帖子

在python中将2位数字拆分为10位和1位数

我正在编写一个程序,用户必须输入0到100之间的数字.然后程序应该将数字分成10和1.因此,如果用户输入23,程序将返回2和3.如果用户输入4,程序将返回0和4.这是我的数字小于10,但我不知道如何处理2使用模运算符的数字.

def split():
    number = int(raw_input("Enter a number between 0 and 100:"))
    if number <10:
        tens = 0
        ones = number
        total = tens + ones
        print "Tens:", tens
        print "Ones:", ones
        print "Sum of", tens, "and", ones, "is", total

split()
Run Code Online (Sandbox Code Playgroud)

谢谢!

python split modulo

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

标签 统计

modulo ×1

python ×1

split ×1