Python basics _Day4 homework

Insert picture description here

(1) Omitted

(2)

while True:
    s = int(input(" enter a student's grade:"))
    if s < 0 or s > 100:
        continue
    else:
        break
grades = "ABCDE"
i = s//10
if i < 6:
    i = 5
if i == 10:
    i = 9
print("{}".format(grades[9-i]))

(3)

x = int(input("please input the x"))
y = int(input("please input the y"))
if x == 0 or y == 0:
    print("点在坐标轴上")
elif x > 0:
    if y > 0:
        print("点在第一象限")
    else:
        print("点在第四象限")
else:
    if y > 0:
        print("点在第二象限")
    else:
        print("点在第三象限")

(4)

Same as the second question

(5)

num_all = 0
num_jishu = 0
num_oushu = 0
i = 1
while i <= 100:
    num_all += i
    if i % 2 == 0:
        num_oushu += i
    else:
        num_jishu += i
    i += 1
print("总和是{0},奇数之和是{1},偶数之"
      "和是{2}".format(num_all, num_jishu, num_oushu))

(6)

num_all = 0
num_jishu = 0
num_oushu = 0
for i in range(1, 101):
    num_all += i
    if i % 2 == 0:
        num_oushu += i
    else:
        num_jishu += i
print("总和是{0},奇数之和是{1},偶数之"
      "和是{2}".format(num_all, num_jishu, num_oushu))

(7)

for i in range(0, 5):
    for j in range(1, 5):
        print(i, end="\t")
    print()

(8)

for i in range(1, 10):
    for j in range(1, i+1):
        print("{0}*{1}={2}".format(i, j, (i*j)), end="\t")
    print()

(9)

r1 = dict(name="gao1", age=18, salary=30000, city="Beijing")
r2 = dict(name="gao2", age=19, salary=20000, city="Shanghai")
r3 = dict(name="gao5", age=20, salary=10000, city="Shenzhen")
table = [r1, r2, r3]
for x in table:
    if x.get("salary") > 15000:
        print(x)

(10)

s = []
i = 0
salary_avg = 0
while True:
    salary = input("输入工资,按Q/q退出")
    if salary.upper() == 'Q':
        break
    if int(salary) < 0:
        print("输入有误,工资请不要倒扣")
        continue
    else:
        s.append(salary)
        salary_avg += int(salary)
        i += 1
salary_avg *= 0.25
print("您已经全部录入{}名员工的薪资".format(i))
print("所有员工的工资是{}".format(s))
print("平均工资是{}".format(salary_avg))

(11)

s = []
i = 0
salary_avg = 0
while i < 4:
    salary = int(input("please enter the salaries of the employee"))
    if salary < 0:
        print("输入有误,工资请不要倒扣")
    else:
        s.append(salary)
        salary_avg += salary
        i += 1
salary_avg *= 0.25
print("您已经全部录入 4名员工的薪资")
print("所有员工的工资是{}".format(s))
print("平均工资是{}".format(salary_avg))

(12)

import turtle

t = turtle.Pen()
t.speed(8)
t.width(5)
t.penup()
t_color = ["red", "blue", "black", "yellow", "green"]
for i in range(10):
    t.color(t_color[i % 5])
    t.goto(0, -10-15*i)
    t.pendown()
    t.circle(10 + 15*i)
    t.penup()
t.hideturtle()
turtle.done()

(13)

import turtle

t = turtle.Pen()
t.speed(10)
t.width(2)
t.penup()
width = 25  # 棋盘每个格子宽25,总宽25*18=450
for i in range(19):
    t.goto(225, 225 - i*25)  # 从右上角的点竖向移动
    t.pendown()
    t.goto(-225, 225 - i*25)  # 沿x轴负方向开始画
    t.penup()
for i in range(19):
    t.goto(225 - i*25, 225)  # 从右上角的点x轴负方向移动
    t.pendown()
    t.goto(225 - i*25, -225)  # 沿竖向开始画
    t.penup()
t.hideturtle()
turtle.done()

Guess you like

Origin blog.csdn.net/tjjyqing/article/details/113148605