정확히 140 자 길이의 문자열을 만듭니다. 나는 break 문과 함께 루프를 사용해야하며, 문자열 목록은 주어진 목록에서 가져온다.Python : 글자 수 제한이 충족되면 루프를 깨는 방법은 무엇입니까?
결국 147 자까지 올라갔습니다. 문자열을 자르는 방법이 있습니까? 그게 당신이 무엇을 원하는 경우
headlines = ["Local Bear Eaten by Man",
"Legislature Announces New Laws",
"Peasant Discovers Violence Inherent in System",
"Cat Rescues Fireman Stuck in Tree",
"Brave Knight Runs Away",
"Papperbok Review: Totally Triffic"]
news_ticker = ""
for headline in headlines:
if len(str(news_ticker)) >= 140:
break
else:
news_ticker = list(news_ticker)
news_ticker.append(headline)
print(news_ticker)
print(len(str(news_ticker)))