Python keyboard input

Source: Internet
Author: User

Python keyboard input is basically similar to other programming languages, enter end input

Let's take a look at the keyboard input month day, English output example:

1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #define the English month4months = ["January","February","March","April"," May","June","July","August","September",5           "October","November","December"]6 #define the end of days7endings = ["St","nd","Rd"] + 17 * ["th"] 8+ ["St","nd","Rd"] + 7 * ["th"] 9+ ["th"]Ten #Enter Month Day OneYear = input ("Year :") Amonth = input ("month (1-12):") -Day = input ("Day (1-31):") - #Convert a month and date to an integer type theMonth_number =Int (month) -Day_number =Int (day) - #get month and day and output -Month_name = Months[month_number-1] +Ordinal = day + endings[day_number-1] - Print(Month_name +' '+ ordinal +' '+ year)

Output Result:

1 year:20172 month (1-12): 23 Day (1-31):4 February 20th 2017

Python keyboard input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.