while True:

プログラミング演習(備瀬 竜馬)

第10回

小問番号はコメント(#)を参照
# 10_A_1
value = input("Input values with space:").split(" ")
values = [int(i) for i in value]
for x in range(len(values)):
    n = values[x]
    print("{:-2} :".format(n), "*" * n)


# 10_A_2
d = [4, 89, 6, 2, 23, 25]
sd = []
for i in range(len(d)):
    sd.append(d[i])
print("sort前", sd)
for i in range(len(d)):
    for j in range(len(d) - i - 1):
        if sd[j] > sd[j + 1]:
            w = sd[j]
            sd[j] = sd[j + 1]
            sd[j + 1] = w
        print(sd)
print("sort後", sd)


# 10_B_1
student_number = []
score = []
while True:
    char = input("学生番号:点数の形式で入力してください。入力を終わるときはexitと入力")
    if char == "exit":
        break
    else:
        char = char.split(":")
        student_number.append(char[0])
        score.append(char[1])
student_number2 = []
score2 = []
for i in range(len(score)):
    score2.append(score[i])
for i in range(len(student_number)):
    student_number2.append(student_number[i])
for i in range(len(score)):
    for j in range(len(score) - i - 1):
        if score2[j] < score2[j + 1]:
            w = score2[j]
            score2[j] = score2[j + 1]
            score2[j + 1] = w
            m = student_number2[j]
            student_number2[j] = student_number2[j + 1]
            student_number2[j + 1] = m
for x in range(len(score2)):
    print("{} score:{} ID:{}".format(x + 1, score2[x], student_number2[x]))


# 10_B_2
char = input("Input values(1-10) with space:").split(" ")
values = [int(i) for i in char]
size = len(values)
for x in range(10):
    for y in range(size):
        if values[y] + x >= 10:
            print("* ", end="")
        else:
            print(" ", end="")
    print()
print("-" * (size * 2 - 1))
for x in range(size):
    print(values[x], end=" ")
print()


# 10_B_3
lists = [[" " for x in range(10)] for y in range(10)]
for x in range(100):
    n = int(input("*の位置を入力(0-99)。終わる場合は-1:"))
    if n == -1:
        break
    else:
        pos_x = n % 10
        pos_y = n // 10
        lists[pos_y][pos_x] = "*"
for x in range(10):
    for y in range(10):
        print(lists[x][y], end="")
    print()


# 10_C_1
n = int(input("生徒の数(≥5):"))
name = []
math = []
chem = []
phys = []
bio = []
average = []
for x in range(n):
    char = input("{}人目 数学の点数:化学の点数:物理の点数:生物の点数 のように入力してください".format(x + 1)).split(":")
    math.append(int(char[0]))
    chem.append(int(char[1]))
    phys.append(int(char[2]))
    bio.append(int(char[3]))
    average.append((int(char[0]) + int(char[1]) + int(char[2]) + int(char[3])) / 4)
s_average = [sum(math) / n, sum(chem) / n, sum(phys) / n, sum(bio) / n]
print("No. |Math |Chem |Phys |Bio |Ave.(person)")
for x in range(n):
    print("{} |{:8}|{:8}|{:8}|{:8}|{:8}".format(x + 1, math[x], chem[x], phys[x], bio[x], average[x]))
print("Ave.(subject)|{:8}|{:8}|{:8}|{:8}|{:8}".format(s_average[0], s_average[1], s_average[2], s_average[3], sum(s_average) / 4))
	
ページのトップへ戻る