나는 어젯밤과 조금은 오늘 아침에 답을 찾으려고했지만 운이 없었다. 숙제의 경우, 우리는 목록을 거쳐 가장 긴 연속 숫자를 반환하도록 요청 받았다. 나는이 코드에 대해 작업 해왔고 숫자 만 정확하게 비교했을 때 첫 번째 숫자와 비교했다. 나는 len (연속 증가)을 알아야합니다.코드 : 숫자 목록을 살펴보고 파이썬의 연속 증가 수를 인쇄하려면 어떻게해야합니까?
#!/usr/bin/python3
import sys
def fOpen(fname):
try:
fd = open(fname,"r")
except:
print("Couldn't open file.")
sys.exit(0)
all = fd.read().splitlines()
fd.close()
return all
words = fOpen(sys.argv[1])
current = []
lastc = []
for x in words:
if len(current) == 0: #Add the first number
current.append(int(x))
elif len(current) == 1: #Check first number < next number
if current[0] < int(x):
current.append(int(x))
else: #elif current[0] >= int(x):
if len(current) >= len(lastc):
lastc = current
current[:] = []
current.append(int(x))
elif len(current) >= 2:
if current[-1] < int(x):
current.append(int(x))
else: #elif current[-1] >= int(x):
if len(current) >= len(lastc):
lastc = current
elif len(current) < len(lastc):
current[:] = []
current[:] = []
current.append(int(x))
print(lastc)
인쇄 진술서는 추적 할 수있게되어 나중에 제거됩니다. 미리 감사드립니다.
이 단어입니까, 아니면이 숫자입니까? – moooeeeep
그래서 ... 학생들은 전문가들이 무료로 숙제를하도록하러갑니다. 너무 많은 것이 돌아 다니고 있습니다. 이 코드에 대해 여러 가지 방법으로 깨졌으며, 휴식 시간을 배우고, 열거를 살펴 봅니다 ... 처음부터 시작하십시오 ... 도움을 청하기 전에 배우십시오. Seth, 미안 해요. –
-1 제목에 "연속 증가"가 있지만 질문 본문에는 "연속 숫자"(매우 모호함)가 있으며 코드 주석에서 "최대 10 개의 정수 찾기"라고 말합니다. 원하는 것을 생각하고 그에 따라 질문을 편집하십시오. –