請問一下我的這段程式碼為什麼第一次輸入E時什麼都沒有輸出,第二次才輸出了正確的答案?
作者:由 陳柚子 發表于 體育時間:2022-03-23
因為 a =
input
(“請輸入索引名(quit退出):”)。lower() 使用了兩次,所以出現兩次 E
簡單改了一下,不知道能不能透過:(呵呵)
import
pandas
as
pd
s
=
pd
。
Series
(
list
(
‘堅實的基礎乃致勝之法寶’
),
index
=
list
(
‘abcdefghijk’
))
(
‘目前 Series:
\n
’
,
s
,
sep
=
‘’
)
while
True
:
a
=
input
(
“請輸入索引名(quit退出):”
)
。
lower
()
a
=
a
。
strip
()
# 去掉首尾空格
if
a
==
‘quit’
:
break
if
a
not
in
‘abcdefghijk’
:
(
“索引名錯誤,請重新輸入!”
)
continue
else
:
b
=
s
。
index
。
tolist
()
。
index
(
a
)
if
1
<=
b
<=
9
:
(
s
[
b
-
1
:
b
+
2
])
if
b
==
0
:
(
s
[
b
:
b
+
2
])
if
b
==
10
:
(
s
[
b
-
1
:
b
+
1
])
下一篇:文科300多分,走單招好進嗎?