Я в настоящее время занимаюсь программированием на программировании на компьютере Python по GCSE, но я столкнулся с некоторой проблемой, и я не могу найти ответ.Чтение и печать специальных строк в Python
У меня есть часть кода, которая должна считываться из файла и печатать часть файла. Мой код можно увидеть ниже:
#Welcome Message
print("Hello and welcome to the client activity recorder. \nHere you will be able to see and asign exercise levels to clients.")
#Open file for reading.
client_file_read = open("clientIntensity.txt","r")
print_content = client_file_read.read()
print(print_content)
#Client Selection
print("Please type the client ID of the person you wish to check what relevant activities apply:")
client_ID = input()
if client_ID == ("NeQua"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
elif client_ID == ("RoDen"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
elif client_ID == ("BrFre"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
elif client_ID == ("KaDat"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
elif client_ID == ("ViRil"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
elif client_ID == ("TrGeo"):
with open("exerciseActivities.txt") as f:
print("For the supplied Client ID the following activities are available: \n")
for x in range (6):
line = f.readline()
print(line)
f.close
else:
with open("exerciseActivities.txt") as f:
Ниже приводится копия файла, который я использую, чтобы читать:
High
Running
Swimming
Aerobics
Football
Tennis
Moderate
Walking
Hiking
Cleaning
Skateboarding
Basketball
Как вы можете видеть суб программу Элифа все печатают первые 6 строки файла, но в последней команде else я хотел бы, чтобы программа печатала последние 6 строк файла выше. Помощь была бы очень признательна, поскольку я исчерпал любые идеи, которые я имею о том, как это сделать.
С наилучшими пожеланиями
Не думаю, что я когда-либо слышал о 'elif's именуемых – Jules