元组的案例演示
2018-06-18 01:54:47来源:未知 阅读 ()
案例一:输入一个数字,转换成中文数字。比如:1234567890 -> 壹贰叁肆伍陆柒捌玖零
方法01:
number = input("请输入一个数字:")
for i in range(len(number)):
if "0" in number[i]:
print("零", end="")
if "1" in number[i]:
print("壹", end="")
if "2" in number[i]:
print("贰", end="")
if "3" in number[i]:
print("叁", end="")
if "4" in number[i]:
print("肆", end="")
if "5" in number[i]:
print("伍", end="")
if "6" in number[i]:
print("陆", end="")
if "7" in number[i]:
print("柒", end="")
if "8" in number[i]:
print("捌", end="")
if "9" in number[i]:
print("玖", end="")
if "." in number[i]:
print("点", end="")
方法02:使用元组
chinese_number = ("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")
number = input("请输入一个数字:")
for i in range(len(number)):
if "." in number[i]:
print("点", end="")
else:
print(chinese_number[int(number[i])], end="")
执行结果:
C:\python\python.exe C:/python/demo/file3.py
请输入一个数字:123.45
壹贰叁点肆伍
Process finished with exit code 0
案例02:根据花色和数字生成一副扑克牌
poker_type = ("?", "?", "?", "?")
poker_number = ("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2")
poker_list = []
for i in poker_number:
for j in poker_type:
poker_list.append(j+i)
print(len(poker_list))
print(poker_list)
执行结果:
C:\python\python.exe C:/python/demo/file3.py
52
['?3', '?3', '?3', '?3', '?4', '?4', '?4', '?4', '?5', '?5', '?5', '?5', '?6', '?6', '?6', '?6', '?7', '?7', '?7', '?7', '?8', '?8', '?8', '?8', '?9', '?9', '?9', '?9', '?10', '?10', '?10', '?10', '?J', '?J', '?J', '?J', '?Q', '?Q', '?Q', '?Q', '?K', '?K', '?K', '?K', '?A', '?A', '?A', '?A', '?2', '?2', '?2', '?2']
Process finished with exit code 0
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:2.1端口扫描器
- 列表和元组 2019-08-13
- 案例 — 使用bs4 爬取猫眼电影热榜 2019-07-24
- python 基础学习笔记(3)--列表与元组 2019-07-24
- python学习-18 元组 2019-07-24
- 切片 2019-05-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash