• python1119-20181205作业-郭恩赐提交


    作业1

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

    s = 'python的创始人是Guido'
    print(s[-5:])
    print(s[:-6:-1])
    print(s[::3])

    作业2

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

    s1 = ''
    s2 = '最帅'
    print (s1+s2)
    print(s1+s2*3)

    作业3

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

    import random
    for i in range(10):
        x = random.randint(0,1000)
        
        ge = x%10
        shi = x//10%10
        bai = x//100
        qian = x//1000
        if ge== shi and bai==0 and qian==0 or ge ==qian and shi == bai
     and qian != 0 or ge==bai and qian==0 and bai != 0:
            print('%d是回文整型数'%x,end=" ")
    
        print(x)

    作业4

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

    for gg in range (0,20):
        for mg in range (0,100//3):
            for xg in range(0,100):
                if mg+gg+xg ==100 and gg*5 + mg*3 + xg //3 ==100:
                    if xg%3 ==0:
                        print('公鸡{}只,母鸡{}只,小鸡{}只'.format(gg,mg,xg))

    作业5

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

      

    s = input('请输入一个字符串:')
    sn=nn=0
    for i in s:
        if "A"<=i<="Z"or 'a'<= i <='z':
            sn+=1
        elif '0'<=i <='9':
            nn+=1
        
    print('字母的个数:{},数字的个数{}'.format(sn,nn))

    作业6

      附加:
            已知1990.1.1是星期一,用户输入一个1990后的>任意年月,计算其1号星期几
            参考命令cal 12 2018

    nian=int(input ('请输入年份:'))
    yue=int(input('请输入月份:'))
    nday =0
    def runnian(nian):
        if nian%4==0 and nian%100!=0 or nian%400==0:
            return True
        else:
            return False
    
    for i in range(1,yue):
        if i ==1 or i ==3 or i ==5 or i == 7 or i ==8 or i ==10 or i ==12:
            myue=31
        elif i == 4 or i == 6 or i ==9 or i ==11:
            myue=30
        else:
            if runnian(nian):
                myue = 29
            else:
                myue=28
        nday=nday+myue
    nnday=0
    for x in range(1990,nian):
        year=365
        if runnian(x):
            year =366
        nnday= year+nnday
    zday =nnday + nday
    print(zday%7+1)
  • 相关阅读:
    LaTeX 超链接
    剑指offer2 数组
    LaTeX 插入源代码
    RGB
    linux 程序在后台运行
    Linux Vim编辑与退出
    复杂度估计
    剑指offer 2 loading...
    剑指offer2 整数
    剑指offer2 字符串
  • 原文地址:https://www.cnblogs.com/gec258/p/10073703.html
Copyright © 2020-2023  润新知