第四章实操

9. 用列表和字典存储下表信息,并打印出表中工资高于15000 的数据


 

r1={"name":"高小一","age":18,"salary":30000,"city":"北京"}
r2={"name":"高小二","age":19,"salary":20000,"city":"上海"}
r3={"name":"高小三","age":20,"salary":10000,"city":"深圳"}
tb = [r1,r2,r3]
for x in tb:
    if x.get("salary") > 15000:
        print(x)

10. 要求输入员工的薪资,若薪资小于0 则重新输入。最后打印出录入员工的数量和薪资明
细,以及平均薪资

num=0
salarysum=0
salarys=[]
while True:
    s=input("请输入工资:")
    if s.upper()=="Q":
        print("输入完成")
        break
    if float(s)<0:
        continue
    num +=1
    salarys.append(float(s))
    salarysum += float(s)
print("员工数量{0},薪资表{1},平均薪资{2}".format(num,salarys,salarysum/num))

11. 员工一共4 人。录入这4 位员工的薪资。全部录入后,打印提示“您已经全部录入4
名员工的薪资”。最后,打印输出录入的薪资和平均薪资

salarys=[]
salarysum=0
for x in range(4):
    s = input("请输入4人工资:")
    if s.upper() == "Q":
        print("输入完成")
        break
    if float(s) < 0:
        continue
    salarys.append(float(s))
    salarysum += float(s)
print("您已经全部录入4 名员工的薪资")
print("薪资表{0},平均薪资{1}".format(salarys,salarysum/4))

12. 使用海龟绘图,绘制同心圆:

import turtle

t = turtle.Pen()
t.width(4)
t.speed(0)
my_colors = ("red","green","yellow","black")
for i in range(10):
    t.penup()
    t.goto(0,-i*10)
    t.pendown()
    t.color(my_colors[i % len(my_colors)])
    t.circle(15+i*10)

t.color("red")

turtle.done()

13. 使用海龟绘图,绘制18*18 的棋盘:

import turtle
t = turtle.Pen()
t.speed(0)
for i in range(19):
    t.penup()
    t.goto(-90,90-i*10)
    t.pendown()
    t.goto(90,90-i*10)
for i in range(19):
    t.penup()
    t.goto(i*10-90,-90)
    t.pendown()
    t.goto(i*10-90,90)
t.hideturtle()
turtle.done()

猜你喜欢

转载自blog.csdn.net/kkaa__/article/details/112966807