Мне нужна помощь с зацикливанием файлов:
inputa = int(input('How many days of data do you have? '))
print('Average Temperatures:')
if inputa == 1:
lst1 = []
lst = []
for line in open('temps1.txt'):
lst1.append(line.rstrip())
lst = lst1
elif inputa == 2:
lst1 = []
lst2 = []
lst = []
for line in open('temps1.txt'):
lst1.append(line.rstrip())
for line in open('temps2.txt'):
lst2.append(line.rstrip())
lst = lst1+lst2
elif inputa == 3:
lst1 = []
lst2 = []
lst3 = []
lst = []
for line in open('temps1.txt'):
lst1.append(line.rstrip())
for line in open('temps2.txt'):
lst2.append(line.rstrip())
for line in open('temps3.txt'):
lst3.append(line.rstrip())
lst = lst1 + lst2 + lst3
Есть ли способ зацикливания файлов.Например, я хочу, чтобы они были temps1.txt
, temps2.txt
, temps3.txt
и так далее, в зависимости от ввода пользователя.Я также хочу иметь lst1[]
, lst2[]
, lst3[]
и так далее.