Python作业题

1.定义一个字符串"python的创始人是Guido",试分别打印出"Guido","odiuG", "ph的人uo"

s = 'python的创始人是Guido'
a = s[11:16:]
b = s[-1:-6:-1]
c = s[::3]
print(a,b,c)

2.有字符串"你"和"最帅",如何得到字符串"你最帅",又如何得到字符串"你最帅最帅最帅" 

s = '你'
s1 = '最帅'
print(s+s1*3)

3. 像121 11 111等对称的整型数称为回文整型数,随机产生1000以内的10个整型数,打印其中的回文整型数 

#回文
import random
for i in range(10):
    n = random.randint(1,1000)
    #print(n)
    s = str(n)
    s_re = s[::-1]
    if s == s_re:
        print('{}是回文'.format(n))
    else:
        print('{}不是回文数'.format(n))

  

  

4. 公鸡5文钱1只,母鸡3文钱1只,小鸡3只1文钱,用100文钱买100只鸡,可以怎么买?

for man in range(21):
    for woman in range(34):
        for kid in range(100):
            if (5*man+3*woman+kid/3)==100 and (man+woman+kid)==100:
                print(man,woman,kid)

  

5. 使用input()读入一个字符串,统计字符串中字母的个数,和数字的个数

a=input("请输入:")
#print(a)
n = 0
s = 0
o = 0
for i in a:
   #print(i)
    if "a"<= i<="z" or "A"<= i<="Z":
       s+=1
    elif '0'<=i<='9':
        n+=1
    else:
        o+=1
print('字母有{}个,数字有{}个,其他有{}个'.format(s,n,o))

6.1990.1.1是星期一,其后任意年月,计算1号星期几

 

 

posted @ 2018-12-05 20:32  米线Max  阅读(238)  评论(0编辑  收藏  举报