Python 编写确定个位、十位以上方法及各数位的和程序

Python 编写确定数字位方法

  • [Python 编写确定个位、十位](#Python 编写确定个位、十位)
  • [Python 编写确定个位、十位、百位](#Python 编写确定个位、十位、百位)
  • 方法解析:
  • [Python 各数位的和程序](#Python 各数位的和程序)

利用%(取余符号)、//(整除)符号。

Python 编写确定个位、十位

python 复制代码
num = 17
a = num % 10 
b = num // 10 
print(a)
print(b)

输出:

7

1

Python 编写确定个位、十位、百位

python 复制代码
num = 754
a = num % 10 # 个位
b = (num % 100) // 10 # 十位
c = num // 100 # 百位
print(a)
print(b)
print(c)

输出:

4

5

7

方法解析:

由此我们可得求数字各位数之和程序:

Python 各数位的和程序

python 复制代码
num = int(input())
last_digit = num % 10
first_digit = num // 10
print("十位数:", first_digit)
print("个位数:", last_digit)
print("和:", last_digit+first_digit)
相关推荐
2501_944875512 分钟前
Go后端工程师
开发语言·后端·golang
该用户已不存在5 分钟前
没有这7款工具,难怪你的Python这么慢
后端·python
听风吟丶8 分钟前
Java 反射机制深度解析:从原理到实战应用与性能优化
java·开发语言·性能优化
serve the people10 分钟前
tensorflow 零基础吃透:RaggedTensor 的不规则形状与广播机制 2
人工智能·python·tensorflow
Hello.Reader11 分钟前
Flink ML 基本概念Table API、Stage、Pipeline 与 Graph
大数据·python·flink
chen_note13 分钟前
Python面向对象、并发编程、网络编程
开发语言·python·网络编程·面向对象·并发编程
她说彩礼65万14 分钟前
C# params使用
开发语言·c#·log4j
信看15 分钟前
树莓派CAN(FD) 测试&&RS232 RS485 CAN Board 测试
开发语言·python
brent42315 分钟前
DAY24推断聚类后簇的类型
python
测试199819 分钟前
一个只能通过压测发现Bug
自动化测试·软件测试·python·selenium·测试工具·bug·压力测试