字符串(百文买百鸡,回文整型数)
1、给定字符串“python的创始人是Guido”,要求输出 Gudio oiduG ph的人uo
s = "python的创始人是Guido" l = len(s) print(s[11:l]) print(s[l:10:-1]) print(s[::3])
2、有字符串"你"和"最帅",如何得到字符串"你最帅",又如何得到字符串"你最帅最帅最帅"
s1 = "你" s2 = "最帅" print(s1+s2) print(s1+s2*3)
3、像121 11 111等对称的整型数称为回文整型数,随机产生1000以内的10个整型数,打印其中的回文整型数
import random i = 0 while i < 10: a = random.randint(0,1000) print(a) if a % 10 == a // 100: print("{}是回文数".format(a)) elif (a % 10 == a //10) and (a % 10 != 0): print("{}是回文数".format(a)) i += 1
4、公鸡5文钱1只,母鸡3文钱1只,小鸡3只1文钱,用100文钱买100只鸡,可以怎么 for x in range(20): for y in range(33): z = 100 - x - y if (z % 3 == 0) and (5 * x + 3 * y + z / 3 == 100): print("公鸡{}只,母鸡{}只,小鸡{}只".format(x,y,z))
5、使用input()读入一个字符串,统计字符串中字母的个数,和数字的个数
s = input("请输入一个字符串:") n = 0 m = 0 for i in s: if i >= "a" and i <= "z": n +=1 elif i >= "A" and i <= "Z": n +=1 elif i >= "0" and i <= "9": m += 1 print("字符个数为{}个,数字的个数为{}个".format(n,m))