quiz_1_previous

quiz_1_previous.pdf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sys
from random import seed, randrange

try:
unknown_seed, dimension = map(int, input("Enter two integers, the second one being 3 or more: ").split())
if dimension < 3:
raise ValueError
except ValueError:
print("Incorrect input, giving up.")
sys.exit()

print(f"The chosen dimension is {dimension}.")
seed(unknown_seed)
sequence_digits = [randrange(10) for _ in range(dimension)]
print(f"Also, I have this sequence of {dimension} digits for you:")
print(sequence_digits)
target = 9


def display_pic1():
print(f"Here is a first picture.\nThere are {dimension - 1} spaces on each side of the star.")
print(" ", "|" + ((dimension - 1) * 2 + 1) * "-" + "|")
print(" ", "|" + ((dimension - 1) * 2 + 1) * " " + "|")
print(" ", "|" + (dimension - 1) * " " + "*" + (dimension - 1) * " " + "|")
print(" ", "|" + ((dimension - 1) * 2 + 1) * " " + "|")
print(" ", "|" + ((dimension - 1) * 2 + 1) * "-" + "|")


"""
|-------------------|
| |
| * |
| |
|-------------------|
[7, 9, 8, 0, 3, 4, 3, 2, 5, 4]
"""

def display_pic2(sequence_digits):
"""
Here is a second picture.
Top and bottom borders are complementary, because:
0 is 9's "complement".
1 is 8's "complement".
2 is 7's "complement".
"""
print(f"Here is a second picture.\nTop and bottom borders are complementary, because:")
dct = {}
sequence_digits_sorted = sorted(sequence_digits, reverse=True)
for item in sequence_digits_sorted:
remain = target - item
dct[item] = remain

for key, value in dct.items():
print(" ", f"{value} is {key}'s \"complement\"")

"""
|7-9-8-0-3-4-3-2-5-4|
| |
| --- |
| |*| |
| --- |
| |
|2-0-1-9-6-5-6-7-4-5|
"""

last_line = []
for item in sequence_digits:
last_line.append(target - item)

# 整形列表转化为字符型列表

first_line_str = [str(e) for e in sequence_digits]

# first_line_str=list(map(str,sequence_digits))
first_line = "-".join(first_line_str)
last_line_str = list(map(str, last_line))
last_line = "-".join(last_line_str)
print(" ", "|" + first_line + "|")
print(" ", "|" + ((dimension - 1) * 2 + 1) * " " + "|")
print(" ", "|" + (dimension - 2) * " " + "---" + (dimension - 2) * " " + "|")
print(" ", "|" + (dimension - 2) * " " + "|*|" + (dimension - 2) * " " + "|")
print(" ", "|" + (dimension - 2) * " " + "---" + (dimension - 2) * " " + "|")
print(" ", "|" + ((dimension - 1) * 2 + 1) * " " + "|")
print(" ", "|" + last_line + "|")

display_pic1()
display_pic2(sequence_digits)

quiz_1_this_year

quiz_1.pdf
sample_test_file_1.txt
sample_test_file_2.txt