質問編集履歴

1

pythonへ変換したコードを追加しました

2019/09/05 06:36

投稿

Naohito4869
Naohito4869

スコア7

test CHANGED
File without changes
test CHANGED
@@ -53,3 +53,77 @@
53
53
  puts drill.sample(tasizan+hikizan)
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ 自分で下記のようにpythonに変換してみたのですが、timelimit exceedのエラーが出てきてしまい、表示できません。どこか間違っている箇所や実行を遅くしてしまっている箇所を指摘していただけると幸いです。
60
+
61
+
62
+
63
+ ```Python
64
+
65
+ import random
66
+
67
+
68
+
69
+ input_line = input().split(" ")
70
+
71
+ addition = int(input_line[0])
72
+
73
+ subtraction = int(input_line[1])
74
+
75
+ count = -0
76
+
77
+
78
+
79
+ sampleQuestion = []
80
+
81
+
82
+
83
+ while count < addition:
84
+
85
+ number1 = random.randint(0,100)
86
+
87
+ number2 = random.randint(0,100)
88
+
89
+ if number1 + number2 > 99:
90
+
91
+ continue
92
+
93
+ if any("#[number1] + #[number2] =" == var for var in sampleQuestion):
94
+
95
+ continue
96
+
97
+ sampleQuestion.append("#[number1] + #[number2] =")
98
+
99
+ count += 1
100
+
101
+
102
+
103
+ count = 0
104
+
105
+ while count < subtraction:
106
+
107
+ number1 = random.randint(0,100)
108
+
109
+ number2 = random.randint(0,100)
110
+
111
+
112
+
113
+ if number1 <= number2:
114
+
115
+ continue
116
+
117
+ if any("#[number1] - #[number2] =" == var for var in sampleQuestion):
118
+
119
+ continue
120
+
121
+ sampleQuestion.append("#[number1] - #[number2] =")
122
+
123
+ count += 1
124
+
125
+
126
+
127
+ print(sampleQuestion.sample(addition + subtraction))
128
+
129
+ ```