9.13作业

完成完整的温度转换程序

  1. while True:
        a = input("摄氏转华氏请按1
    华氏转摄氏请按2
    ")
        if a == '1':
            c = float(input('请输入摄氏温度:'))
            f =(c * 1.8) + 32
            print('{:.2f}摄氏温度转为华氏温度为{:.2f}'.format(c,f))
        elif a == '2':
            f = float(input('请输入华氏温度:'))
            c = 5 / 9 * (f - 32)
            print('{:.2f}华氏温度转为摄氏温度为{:.2f}'.format(f,c))
        else:
            break

  2. 猜数字游戏(猜价格,猜年龄等)

    num = 6
    gus = -1
    while (gus != num):
        gus =int(input('请输入你要猜测的数字:'))
        if (gus < num):
            print ('你猜的数字太小了!')
        elif (gus > num):
            print('你猜的数字太大了!')
        else:
            print('你猜对了!')
            break

  3. 解析身份证号、学号不同片段的含义
    #解析身份证号
    myid = '441401199404051824'
    print('省份:'+str(myid[0:2]))
    print('所在地区:'+str(myid[2:6]))
    print('出生年月:'+str(myid[6:14]))
    print('派出所编号:'+str(myid[14:16]))
    print('性别:'+str(myid[16]))
    print('校验位:'+str(myid[17]))
    
    #解析学号
    myxh = '201606050088'
    print('年级:{}
    专业:{}
    班级:{}
    序号:{}'.format(myxh[0:4],myxh[4:8],myxh[8:10],myxh[10:12]))

  4. 字符串的:连接,重复,in判断
    
    
    a='满天的乌云又能怎样,'
    b='穿越过就是阳光!'
    print(a+b)

    c='you must study hard !'
    print(c*3)

    d='1,2,3,4,5,6'
    print('6' in d)
    print('7' in d)
     

  5. 用for循环产生一系列网址
    for i in range(0,10,2):  #查询0-10条校园新闻中的偶数网址
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/' + str(i) + '.html')   #方法一
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))    #方法二

  6. 用for循环遍历字符串
    a='hello world'
    for i in a:
        print(i)

原文地址:https://www.cnblogs.com/Tlzlykc/p/9639629.html