python程序 问题求解【例7.6】 编写代码,判断一个字符属于阿拉伯数字,大写字母,小写字母或其他字符? Python 2.7版本 编写一个程序,输入一个字符串,判断...
python\uff0c\u7f16\u5199\u7a0b\u5e8f\uff0c\u7edf\u8ba1\u5927\u5c0f\u5199\u5b57\u6bcd\uff0c\u6570\u5b57\u53ca\u5176\u4ed6\u5b57\u7b26\u7684\u6570\u91cf\uff0c\u5e76\u4ee5\u5b57\u5178\u5f62\u5f0f\u8f93\u51faa = "aAsmr3idd4bgs7Dlsf9eAF"
\u8bf7\u5c06a\u5b57\u7b26\u4e32\u7684\u6570\u5b57\u53d6\u51fa\uff0c\u5e76\u8f93\u51fa\u6210\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002
\u8bf7\u7edf\u8ba1a\u5b57\u7b26\u4e32\u51fa\u73b0\u7684\u6bcf\u4e2a\u5b57\u6bcd\u7684\u51fa\u73b0\u6b21\u6570\uff08\u5ffd\u7565\u5927\u5c0f\u5199\uff0ca\u4e0eA\u662f\u540c\u4e00\u4e2a\u5b57\u6bcd\uff09\uff0c\u5e76\u8f93\u51fa\u6210\u4e00\u4e2a\u5b57\u5178\u3002 \u4f8b {'a':3,'b':1}
\u8bf7\u53bb\u9664a\u5b57\u7b26\u4e32\u591a\u6b21\u51fa\u73b0\u7684\u5b57\u6bcd\uff0c\u4ec5\u7559\u6700\u5148\u51fa\u73b0\u7684\u4e00\u4e2a,\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u3002
\u4f8b \uff1a'aAsmr3idd4bgs7Dlsf9eAF'\uff0c\u7ecf\u8fc7\u53bb\u9664\u540e\uff0c\u8f93\u51fa 'asmr3id4bg7lf9e'
a="aAsmr3idd4bgs7Dlsf9eAF"
def fun1_2(x):#1&2
x=x.lower()#\u5927\u5c0f\u5199\u8f6c\u6362
num=[]
dic={}
for i in x:
if i.isdigit():#\u5224\u65ad\u5982\u679c\u4e3a\u6570\u5b57\uff0c\u8bf7\u5c06a\u5b57\u7b26\u4e32\u7684\u6570\u5b57\u53d6\u51fa\uff0c\u5e76\u8f93\u51fa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32
num.append(i)
else:#2\u8bf7\u7edf\u8ba1a\u5b57\u7b26\u4e32\u51fa\u73b0\u6bcf\u4e2a\u5b57\u6bcd\u7684\u51fa\u73b0\u6b21\u6570\uff08\u5ffd\u89c6\u5927\u5c0f\u5199\uff09\uff0c\u5e76\u8f93\u51fa\u4e00\u4e2a\u5b57\u5178\u3002\u4f8b\uff1a{'a':3,'b':1}
if i in dic:
continue
else:
dic=x.count(i)
new=''.join(num)
print"the new numbers string is:"+new
print"the dictionary is:%s"%dic
fun1_2(a)
def fun3(x):
x=x.lower()
new3=[]
for i in x:
if i in new3:
continue
else:
new3.append(i)
print''.join(new3)
fun3(a)
\u6269\u5c55\u8d44\u6599\uff1aprintf\u51fd\u6570\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879
1\u3001\u57df\u5bbd
%d\uff1a\u6309\u6574\u578b\u6570\u636e\u7684\u5b9e\u9645\u957f\u5ea6\u8f93\u51fa\u3002
\u5982\u679c\u60f3\u8f93\u51fa\u6307\u5b9a\u5bbd\u5ea6\u53ef\u4ee5\u6307\u5b9a\u57df\u5bbd\uff0c%md-->m\u57df\u5bbd,\u6253\u5370\u51fa\u6765\u4ee5\u540e\uff0c\u5728\u63a7\u5236\u53f0\u4e0a\uff0c\u663e\u793am\u4f4d\uff1b
\u5982\u679c\u8981\u6253\u5370\u7684\u6570\u7684\u4f4d\u6570\u5982\u679c\u8d85\u8fc7\u6211\u4eec\u8bbe\u5b9am\u5219\u539f\u6837\u8f93\u51fa\uff1b
\u5982\u679c\u8981\u6253\u5370\u7684\u6570\u7684\u4f4d\u6570\u5982\u679c\u5c0f\u4e8e\u8bbe\u5b9a\u7684\u4f4d\u6570\uff0c\u5219\u8865\u7a7a\u767d\uff0c\u5177\u4f53\u5982\u4e0b:
\u5982\u679cm\u4e3a\u6b63\u6570\uff0c\u5219\u5de6\u5bf9\u9f50(\u5de6\u4fa7\u8865\u7a7a\u767d)\uff1b
\u5982\u679cm\u4e3a\u8d1f\u6570\uff0c\u5219\u53f3\u5bf9\u9f50(\u53f3\u4fa7\u8865\u7a7a\u767d)\u3002
2\u3001\u8f6c\u4e49\u5b57\u7b26
\u5982\u679c\u60f3\u8f93\u51fa\u5b57\u7b26"%"\uff0c\u5219\u5e94\u8be5\u5728\u201c\u683c\u5f0f\u63a7\u5236\u201d\u5b57\u7b26\u4e32\u4e2d\u7528\u8fde\u7eed\u4e24\u4e2a%\u8868\u793a\u3002
\u5982\uff1aprintf("%f%%",1.0/3)\uff1b\u8f93\u51fa\u7ed3\u679c\uff1a0.333333%\u3002
#\u7528\u6240\u7ed9\u5b57\u7b26\u4e32\u6d4b\u8bd5\u4e86\u4e00\u4e0b\uff0c\u53ef\u884cdef string_judg(string): for char in string: if char>='A' and char <='Z': print 'false' return print 'true'string=raw_input('input string:')string_judg(string)
tc = 'n'
while tc:
a =input("请输入字符(退出请输入q):")
if a =='q':
break
if a.isdigit() :
print("输入的是阿拉伯数字:{}".format(a))
elif a.isalpha ():
if a.isupper():
print("输入的是大写字母:{}".format(a))
else:
print("输入的是小写字母:{}".format(a))
else:
print("输入的是其它字符:{}".format(a))
没有问题,我帮你。
扩展阅读:python进入 ... python实训中遇到的困难 ... python入门考试题库及答案 ... python入门教程完整版 ... python struct pack ... python 在线选择题 ... python解决生活小问题 ... python remove ... 用python解决鸡兔同笼问题 ...