0

Good morning!!! Would you mind helping me please? Input:1 output: Day 1 pull_ups 8

file = open("/usercode/files/pull_ups.txt", "r") n = int(input()) print (file.readlines()) file.close()

14th May 2021, 3:54 PM
Hemmily Beatriz Castillo Arrieta
Hemmily Beatriz Castillo Arrieta - avatar
2 ответов
+ 1
file outputs list of sentences as shown in code snippet below. the n input can be used as the index for the list. so if n=0, the output will be "Day 0, 8 pull ups". if n=8 the output will be "Day 8, 10 pull ups". below is the code you can use to get the desired outcome. i am using the context manager (with open(...) as variable:) because it will automatically close the file for you when it exits the with statement. i then added the n input after file.readlines as the index to return the sentence at that index/location. i hope this explains the code and answers your question. with open("/usercode/files/pull_ups.txt", "r") as file: n = int(input()) line_output = file.readlines()[n] print(line_output) https://code.sololearn.com/cZeQrbISue4u/?ref=app
14th May 2021, 4:18 PM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 1
Thank you so much Andrew!
14th May 2021, 4:38 PM
Hemmily Beatriz Castillo Arrieta
Hemmily Beatriz Castillo Arrieta - avatar