1 Star 0 Fork 0

zoey/python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
idcheck.py 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
zoey 提交于 2016-06-03 22:16 +08:00 . add idcheck.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'用于检查标识符的合法性'
import string, keyword
alphas = string.letters + '_'
nums = string.digits
print('欢迎来到标识符检查器 版本:1.0')
print('提示:输入不能为空,直接回车退出检查器!')
print
while True:
try:
myInput = raw_input('请输入你所要检查的标识符>')
except (EOFError,KeyboardInterrupt,IndexError):
print
print('非常抱歉,您的非法输入产生了一个EOF错误或是KeyboardInterrupt异常,你是否输入了^D或者^C?请重新打开检查器。')
break
if len(myInput) > 0:
if myInput[0] not in alphas:
print('无效:第一个字符必须为字母或下划线')
print
else:
for otherChar in myInput[1:]:
if otherChar not in alphas+nums:
print('无效:标识符中不能含有除字母、数字、下划线外的其他字符')
print
break
else:
if myInput in keyword.kwlist:
print('你输入的标识符为关键字')
print
else:
print('检测通过,合法标识符')
print
else:
print('感谢您的使用,编程愉快!')
break
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zoeywoohoo/python.git
git@gitee.com:zoeywoohoo/python.git
zoeywoohoo
python
python
master

搜索帮助