python鍵盤輸入與其他程式語言基本類似,回車鍵結束輸入
下面來看一段鍵盤輸入年月日,英文輸出示例:
1#!/usr/bin/env python2#
_*_ 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]
20print(month_name + '
' + ordinal + '
' + year)
輸出結果:
1 year:20172 month(1-12):2
3 day(1-31):20
4 february 20th 2017
Python模擬鍵盤輸入
2.程式實現 import win32api import win32con win32api.keybd event 17,0,0,0 ctrl鍵位碼是17 win32api.keybd event 86,0,0,0 v鍵位碼是86 win32api.keybd event 86,0,win32c...
Python讀取鍵盤輸入
python提供了兩個內建函式從標準輸入讀入一行文字,預設的標準輸入是鍵盤。如下 raw input 函式從標準輸入讀取乙個行,並返回乙個字串 去掉結尾的換行符 str raw input enter your input print received input is str 這將提示你輸入任意字...
python獲取鍵盤輸入
raw input函式 raw input 函式從標準輸入讀取乙個行,並返回乙個字串 去掉結尾的換行符 str raw input enter your input print received input is str 這將提示你輸入任意字串,然後在螢幕上顯示相同的字串。當我輸入 hello py...