6.定义一个字符串"python的创始人是Guido",试分别打印出"Guido","odiuG", "ph的人uo"
a = "python的创始人是Guido" print(a[11:]) print(a[-1:-6:-1]) print(a[::3])
7.有字符串"你"和"最帅",如何得到字符串"你最帅",又如何得到字符串"你最帅最帅最帅"
a = "你" b = "最帅" print(a + b) print(a + b * 3)
2. 像121 11 111等对称的整型数称为回文整型数,随机产生1000以内的10个整型数,打印其中的回文整型数
import random i = 0 for i in range(10): a = random.randint(1, 1000) if a > 99: if a%10 == a//100: print(a) else: if a%10 == a//10: print(a)
4. 公鸡5文钱1只,母鸡3文钱1只,小鸡3只1文钱,用100文钱买100只鸡,可以怎么买?
""" 定义公鸡个数为:a 定义母鸡个数为:b 小鸡个数位:c """ a = 0 b = 0 c = 0 for a in range(21): for b in range(34): for c in range(300): if 5*a+3*b+c/3==100 and a+b+c==100: print(a, b, c, )
5. 使用input()读入一个字符串,统计字符串中字母的个数,和数字的个数
a = str(input("请输入一个字符串:")) i = 1 shuzi = 0 zimu = 0 for i in range (len(a)): c = (a [i:i+1]) if c >= "0" and c <= "9": shuzi += 1 else: c = (a[i:i+1]) c >= "a" and c <= "z" zimu +=1 print(shuzi) print(zimu)
已知1990.1.1是星期一,用户输入一个1990后的任意年月,计算其1号星期几
参考命令cal 12 2018