编写python程序-进行逐个取位

#欢迎观看我的CSDN
id = int(input("随意输入四位数:"))
x1 = id % 10  # 取个位数
x2 = id // 10 % 10  # 取十位数
x3 = id // 100 % 10  # 取百位数
x4 = id // 1000  # 取千位数
print(" 个位数为:{},十位数为:{},百位数为:{},千位数为:{}".format(x1, x2, x3, x4))

#第二种方法
id =input("随意输入四位数:")
a=id[0]  # 取个位数
b=id[1]  # 取十位数
c=id[2]  # 取百位数
d=id[3]  # 取千位数
print("千位数:{},百位数:{},十位数:{},个位数:{}".format(a,b,c,d))

猜你喜欢

转载自blog.csdn.net/m0_62491934/article/details/121180843