문제 설명
결과를 세로 방향으로 저장하는 방법 (How do i save the result in a Vertical direction)
#This is a solarcell simulator.
def save(result):
with open('text.txt', 'w') as file:
file.write(result)
def main():
result = []
while True:
val=int(input("Do you want to check a new latitude? 1.yes 2.No" ))
if val == 1:
print("lets go")
lat=latitude()
result.append(calc(lat))
elif val==2:
print ("Bye!")
spara(str(result))
break
else:
print("yes or no")
이것은 text.txt
파일에서 얻은 것입니다.
[(1, 289.4736790328647), (2, 301.5078692306731)]
하지만 이것이 제가 원하는 것입니다
[(1, 289.4736790328647)
(2, 301.5078692306731)]
참조 솔루션
방법 1:
if result
is a list of tuples then this would work:
file.write('[' + '\n'.join(map(str,result)) + ']')
(by burhan hashi、Ayush)