标签:new 元素 基础 not art cond 大写 pre result
·数字个数
str=input() cnt=0; for i in range(len(str)): if(str[i].isdigit()): cnt+=1 print(cnt)
Caesar Secret
str=input("请输入一个字符串:") caesar="" n=input("请输入秘钥:") n=int(n) for ch in str: caesar += chr(97+(ord(ch)+n-97)%26) print(caesar)
·日期(升级版)
week=[‘Monday‘,‘Tuesday‘,‘Wednesday‘,‘Thurday‘,‘Friday‘,‘Saturday‘,‘Sunday‘] while True: myStr=input("请输入任意一个字母:") upMyStr=myStr.upper() for weeks in week: if upMyStr == weeks[0]: if weeks.startswith("M"): print("星期一") elif weeks.startswith("W"): print("星期三") elif weeks.startswith("F"): print("星期五") elif weeks.startswith("T") or weeks.startswith("S"): secondStr=input("请再输入任意一个字符:") newStr=upMyStr+secondStr print(newStr) for weekStr in week: if weekStr.find(newStr,0,2)!=-1: if newStr == "Tu": print("星期二") elif newStr == "Th": print("星期四") elif newStr == "Sa": print("星期六") elif newStr == "Su": print("星期日") break break
·数字个数(升级版)
str=input() cnt=0; cnt2=0; cnt3=0; for num in str: if num.isdigit(): cnt+=1 if num.isupper(): cnt2+=1 if num.islower(): cnt3+=1 print("数字个数为%d"%cnt) print("大写字母个数为%d"%cnt2) print("小写字母个数为%d"%cnt3)
·删除列表中重复元素
list_A = [‘python‘,‘语‘,‘言‘,‘是‘,‘一‘,‘门‘,‘动‘,‘态‘,‘语‘,‘言‘] #print(list(set(list_A))) resultList=[] for item in list_A: if not item in resultList: resultList.append(item) print(resultList)
·选择法排序
list_demo=[5,6,9,2,0,3] for i in range(len(list_demo)-1): p=i for j in range(i+1,len(list_demo)): if(list_demo[p]>list_demo[j]): p=j temp=list_demo[p] list_demo[p]=list_demo[i] list_demo[i]=temp print(list_demo)
·抓狐狸
import random Map = [0,0,0,0,0] num = [-1,1] pre = random.randint(0,4) Map[pre] = 1 cnt = 1 while True: if cnt == 5: print("哎,你没机会啦~") break print("你想打开哪个洞口(0~4):") now = int(input()) if now not in [0,1,2,3,4]: print("别调皮,重新输入~") continue if Map[now] == 1: print("恭喜你!抓到狐狸啦~") print(Map) break else: print(Map) Map[pre] = 0 pos = random.choice(num) pre = (pre + pos) if pre == 5: pre = 0 elif pre == -1: pre =4 Map[pre] = 1 print("你没有抓到哦~") cnt += 1
标签:new 元素 基础 not art cond 大写 pre result
原文地址:https://www.cnblogs.com/zhang-a-d/p/14823096.html