博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 键盘输入
阅读量:7076 次
发布时间:2019-06-28

本文共 812 字,大约阅读时间需要 2 分钟。

python键盘输入与其他编程语言基本类似,回车键结束输入

下面来看一段键盘输入年月日,英文输出示例:

1 #!/usr/bin/env python 2 # _*_ coding:utf-8 _*_ 3 # 定义英文月份 4 months = ["january", "February", "March", "April", "May", "June", "july", "August", "September", 5           "October", "November", "December"] 6 # 定义天数结尾 7 endings = ["st", "nd", "rd"] + 17 * ["th"] \ 8           + ["st", "nd", "rd"] + 7 * ["th"] \ 9           + ["th"]10 # 输入年月日11 year = input("year:")12 month = input("month(1-12):")13 day = input("day(1-31):")14 # 将月份和日期转换为整型15 month_number = int(month)16 day_number = int(day)17 # 获取年月日并输出18 month_name = months[month_number - 1]19 ordinal = day + endings[day_number - 1]20 print(month_name + ' ' + ordinal + ' ' + year)

输出结果:

1 year:20172 month(1-12):23 day(1-31):204 February 20th 2017

 

转载于:https://www.cnblogs.com/zhangyating/p/8124503.html

你可能感兴趣的文章