zoukankan      html  css  js  c++  java
  • 每日一程-5. Python 打印年月日

    Author: Notus(hehe_xiao@qq.com)
    Create: 2019-02-12
    Update: 2019-02-12

    输入年月日, 以数字形式打印

    Python 版本: 2.7.11

    代码如下

    # -*- coding: utf-8 -*-
    '''
    	根据给定的年月日以数字的形式打印出日期
    	@Author: Notus(hehe_xiao@qq.com)
    	@Create: 2019-02-12
    	@Update: 2019-02-12
    '''
    
    months = [
    	'January', 
    	'February', 
    	'March', 
    	'Apirl', 
    	'May', 
    	'June', 
    	'July', 
    	'August', 
    	'September', 
    	'October', 
    	'November',
    	'December'
    ]
    
    # 以1~31的数字作为结尾的列表
    endings = ['st', 'nd', 'rd'] + 17 * ['th'] 
    	+ ['st', 'nd', 'rd'] + 7 * ['th'] 
    	+ ['st']
    
    year = raw_input('Year: ')
    month = raw_input('Month(1-12): ')
    day = raw_input('Day(1-31): ')
    
    month_number = int(month)
    day_number = int(day)
    
    # 月份和天数减1,以获得正确的索引
    month_name = months[month_number - 1]
    ordinal = day + endings[day_number - 1]
    
    print month_name + ' ' + ordinal + '. ' + year
    
    

    运行结果

    Year: 2017
    Month(1-12): 3
    Day(1-31): 4
    March 4th. 2017

  • 相关阅读:
    DOS net use
    DOS cscript
    DOS bcp
    DOS ftp
    java 锁机制(synchronized 与 Lock)
    java-过滤器(Filter)
    java collection集合
    java Map集合对比分析
    java反射与注解结合使用(根据传入对象输出查询sql)
    java反射-使用反射来操纵方法
  • 原文地址:https://www.cnblogs.com/leo1875/p/10363753.html
Copyright © 2011-2022 走看看