import sys
for s in sys.stdin:
if(len(s)>2):
x=s.split()
if((int(x[1])-int(x[0]) == int(x[2])-int(x[1])) and (int(x[2])-int(x[1]) == int(x[3])-int(x[2]))):
print(s+" "+str(int(x[3])+(int(x[3])-int(x[2]))))
else:
print(s+" "+str(int(int(x[3])*(int(x[3])/int(x[2])))))
在VScode裡面是可以把字串加起來的,但是在測試時就只會有list本身,如1 2 3 4,我後面要加的str(int(x[3])+(int(x[3])-int(x[2])))會直接消失,但是如果在測試裡單印str(int(x[3])+(int(x[3])-int(x[2])))又可以出現5,這到底怎麼回事?
import sys
for s in sys.stdin:
if(len(s)>2):
x=s.split()
if((int(x[1])-int(x[0]) == int(x[2])-int(x[1])) and (int(x[2])-int(x[1]) == int(x[3])-int(x[2]))):
print(s+" "+str(int(x[3])+(int(x[3])-int(x[2]))))
else:
print(s+" "+str(int(int(x[3])*(int(x[3])/int(x[2])))))
在VScode裡面是可以把字串加起來的,但是在測試時就只會有list本身,如1 2 3 4,我後面要加的str(int(x[3])+(int(x[3])-int(x[2])))會直接消失,但是如果在測試裡單印str(int(x[3])+(int(x[3])-int(x[2])))又可以出現5,這到底怎麼回事?
s 後面有換行符號。
import sys
t = int(sys.stdin.readline())
for i in range(t):
# s 後面會有換行符號
# 如果會列印 s 可先用 strip 去掉
s = sys.stdin.readline().strip()
# 把 s 切成 list 順便轉成 int
x = [int(c) for c in s.split()]
# x = list(map(int, s.split()))
if(x[1]-x[0] == ...
print(s, ...
# 列印會幫你加空白
import sys
t = int(sys.stdin.readline())
for i in range(t):
# s 後面會有換行符號
# 如果會列印 s 可先用 strip 去掉
s = sys.stdin.readline().strip()
# 把 s 切成 list 順便轉成 int
x = [int(c) for c in s.split()]
# x = list(map(int, s.split()))
if(x[1]-x[0] == ...
print(s, ...
# 列印會幫你加空白
感謝回應!