• 2019/1/22 练习作业


    一、while:

    isinstance是Python中的一个内建函数。是用来判断一个对象的变量类型

    while True:
    print('请输入你的年龄:')
    Age = input()
    if Age.isdecimal():
    break
    print('输入错误,请重新输入')
    Department = input('请输入你所在的部门:')
    Movive = input('请输入你喜欢的电影:')
    print(Age,Department,Movive)

    虽然实现了age里面的判断,但未实现整个的循环。

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    # -*- coding: UTF-8 -*-
    # Author:jiaoyutao
    import time
    import logging

    logging.basicConfig(level=logging.DEBUG,
    format='%(asctime)s: %(levelname)s >>>: %(message)s',
    filename='2019年python第一课程序日志-焦玉涛.log',
    filemode='w')

    #定义一个StreamHandler,将INFO级别或更高的日志信息打印到标准错误,并将其添加到当前的日志处理对象#
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    formatter = logging.Formatter('%(levelname)-8s %(message)s')
    console.setFormatter(formatter)
    logger = logging.getLogger('')
    logger.addHandler(console)

    logger.info("****************第一题****************")
    # 第一题:将西安存储到变量first_name中,将兴汇存储到变量last_name中,将这两个变量拼接到一起输出。
    first_name = "西安"
    last_name = "兴汇"
    company = first_name + last_name
    logger.info(company)
    time.sleep(1)

    logger.info("****************第二题****************")
    # 第二题:每个同事通过input结合字符串拼接实现:输入自己部门、年龄、姓名、喜欢的电影、一起打印了屏幕上。
    name = input("姓名:")
    logger.debug("输入姓名:"+ name)
    while True:
    age = input("年龄:")
    logger.debug("输入年龄:" + age)
    if age.isdigit():
    age = int(age)
    if 60 > age > 20:
    logger.warning("【提示】:年龄符合要求!")
    break
    elif age < 20:
    logger.warning("【警告】:要点脸,请不要骗自己!")
    elif age > 60:
    logger.warning("【警告】:大叔呀,这么老了,您应该退休了!")
    else:
    logger.warning("【警告】:小样,你好好滴,请重新输入!")
    department = input("部门:")
    logger.debug("输入部门:"+ department)
    movie = input("最喜欢的电影:")
    logger.debug("输入最喜欢的电影:"+ movie)
    haha = "我叫%s,今年%d岁,我属于%s部门,我最喜欢的电影为《%s》。"%(name,age,department,movie)
    logger.info(haha)
    time.sleep(1)

    logger.info("****************第三题****************")
    #第三题:用户输入日期. 然后判断日期. 根据日期, 查询值班人员。
    logger.debug("********【你好,欢迎使用SDC值班查询神器】********")
    def zhiban(riqi):
    if riqi in ["1", "6"]:
    logger.info("今天值班人员为:焦玉涛")
    elif riqi in ["2", "7"]:
    logger.info("今天值班人员为:陈永兴")
    elif riqi in ["3", "8"]:
    logger.info("今天值班人员为:卫春喜")
    elif riqi in ["4", "9"]:
    logger.info("今天值班人员为:周凯旋")
    elif riqi in ["5", "0"]:
    logger.info("今天值班人员为:任朝朝")

    while True:
    date = input("请输入要查询的值班日期(格式XX.XX):")
    logger.debug("输入查询日期:" + date)
    Month = date.split(".")[0]

    if Month in ["1", "3", "5", "7", "8","10", "12", "01", "03", "05","07", "08"]:
    Day = date.split(".")[1]
    if 0 < int(Day) < 32:
    zhiban(Day[-1])
    break
    else:
    logger.error("【错误提示】:请按照格式输入正确的日期!")
    elif Month in ["4","6","9","11","04","06","09"]:
    Day = date.split(".")[1]
    if 0 < int(Day) < 31:
    zhiban(Day[-1])
    break
    else:
    logger.error("【错误提示】:请按照格式输入正确的日期!")
    elif Month in ["2","02"]:
    Day = date.split(".")[1]
    if 0 < int(Day) < 29:
    zhiban(Day[-1])
    break
    else:
    logger.error("【错误提示】:请按照格式输入正确的日期!")
    else:
    logger.error("【错误提示】:请按照格式输入正确的日期!")

    logger.info("*********程序将在3秒后自动退出*********")
    time.sleep(3)

    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    import easygui

    first_name = "西安"
    last_name = "兴汇"
    easygui.msgbox(first_name+last_name)
    print(first_name+" "+last_name)

    # -*- coding:utf-8 -*-
    import easygui as g
    file=open("调查问卷.xlsx","w")
    global Result
    def New_Ask():
    # global Department
    # global Age
    # global Name
    # global Favorite_Movie
    Department = g.enterbox("请输入你的部门:",title="调查文卷")
    Age = g.integerbox("请输入你的年龄:",title="调查文卷")
    Name = g.enterbox("请输入你的姓名:",title="调查文卷")
    Favorite_Movie = g.enterbox("请输入你最喜欢的电影:",title="调查文卷")

    if g.ccbox("我的部门:" + Department + " " + "我的年龄:" + str(Age) + " " + "我的姓名:" +
    Name + " " + "我最喜欢的电影:" + Favorite_Movie,title="调查文卷",choices=("正确", "错误")):
    file.write( "我的部门:" + Department + " " + "我的年龄:" + str(Age) + " " + "我的姓名:" +
    Name + " " + "我最喜欢的电影:" + Favorite_Movie)
    else:
    New_Ask()
    if __name__ == '__main__':
    New_Ask()
    file.close()

    ****************************************************************************************************************************************************************

    第二题:随机一次输入一个年份,现必须输入三次,并且判断是不是闰年?

    # def Leap_Year(args):
    #     for year in args:
    #         if year % 4 ==0 and year % 100 != 0 or year % 400 == 0:
    #             print('[%s]这一年是闰年' % year)
    #         else:
    #             print('[%s]这一年不是闰年' % year)
    #
    # if __name__ == '__main__':
    #     Year_List = []
    #     while len(Year_List) < 3:
    #         year = int(input('请输入年份:').strip())
    #         Year_List.append(year)
    #     Leap_Year(Year_List)

    note:使用这个结构可以将输入一次执行一次变为一次性全部输入后再挨个执行。

    ***************************************************************************************************************************

    作业:计算字符串s中所有数字的和 s='1234adg3g11' 连续数字要当做一个数处理;

    s = '1234adg3g11'
    ss = s[0:4]
    print(ss)
    sss = list(ss)
    ssss = []
    for i in ss:
        l = int(i)
        ssss.append(l)
    print(ssss)
    S = sum(ssss)
    print(S)

    1、首先尝试使用strip函数,发现此方法只能清除字符串首尾的元素,中间的无能为力,于是采用字符串按位截取的方法;

    2、截取成功后ss还是字符串,我想通过sum函数对其求和,sum函数是对可迭代对象求和的,意思是对元组,列表有用的,于是我使用list函数将其转换为列表;

    3、sum(sss)后报错,查看后原来使用直接list的方式将字符串转换为列表,列表里的元素各个都是字符串,无法使用sum,纵使直接通过for循环遍历依然会存入字符串;

    4、最后通过i的转换,实现功能;

  • 相关阅读:
    windows10 + anaconda + tensorflow-1.5.0 + python-3.6 + keras-2.2.4配置和安装
    k-center问题-学习
    交换机+路由器 网络口连接桥接关系示意
    用scp命令来通过ssh传输文件,ssh推送.py程序到CentOS7服务器端出现lost connection错误
    codevs 1519 过路费 最小生成树+倍增
    10.18 noip模拟试题
    poj 3565 ants
    [国家集训队2011]种树 (神贪心~~)
    poj 1821 Fence 单调队列优化dp
    SPFA 小优化*2
  • 原文地址:https://www.cnblogs.com/zhao-zhao/p/10305234.html
Copyright © 2020-2023  润新知