python20181205
6.定义一个字符串"python的创始人是Guido",试分别打印出"Guido","odiuG", "ph的人uo"
n = "python的创始人是Guido" print(n[11:16]) print(n[-1:-6:-1]) print(n[::3])
7.有字符串"你"和"最帅",如何得到字符串"你最帅",又如何得到字符串"你最帅最帅最帅"
m = "你" n = "最帅" print(m+n) print(m+n*3)
2. 像121 11 111等对称的整型数称为回文整型数,随机产生1000以内的10个整型数,打印其中的回文整型数
from random import* for i in range (10): m=randint(0,1001) n=str(m) if n == n[::-1]: print(n)
4. 公鸡5文钱1只,母鸡3文钱1只,小鸡3只1文钱,用100文钱买100只鸡,可以怎么买?
for i in range(100): for j in range(100): for z in range(100): if 5*i+3*j+z/3 == 100: if i+j+z==100: print("{}个公鸡,{}个母鸡,{}小鸡".format(i,j,z))
5. 使用input()读入一个字符串,统计字符串中字母的个数,和数字的个数
s = input("请输入一个字符串:") cnt = 0 num = 0 for i in s: if "A" <= i <= "z": cnt += 1 elif "0" <= i <= "9": num += 1 print("字母的个数{},数字的个数{}".format(cnt,num))
已知1990.1.1是星期一,用户输入一个1990后的任意年月,计算其1号星期几
year = int(input("请输入一个年份:")) month = int(input("请输入一个月份:")) day = int(input("请输入一个日期:")) l = 0 m = year - 1990 for i in range (1990,year): if i % 4 ==0 and i % 100 != 0 or i % 400 ==0: l += 1 d = 365 * (m - l) + 366 * l if year % 4 ==0 and year % 100 != 0 or year % 400 ==0: da = [31,29,31,30,31,30,31,31,30,31,30,31] else: da = [31,28,31,30,31,30,31,31,30,31,30,31] days = 0 for i in range(1,13): if i == month: for j in range(i-1): days +=da[j] n = days + day t = (d + n) % 7 if t == 1: print("1号是星期一") elif t == 2: print("1号是星期二") elif t == 3: print("1号是星期三") elif t == 4: print("1号是星期四") elif t == 5: print("1号是星期五") elif t == 6: print("1号是星期六") else: print("1号是星期日")