+ 5

Files

Hello, does someone know how to do this problem? I’m doing it wrong Tom has done pull ups every day and recorded his results. He recorded each day's results in a new line, so that each line represents each day he has done pull ups. Create a program that takes n number as input and outputs the n-th days result (starting from 0). Sample Input 4 Sample Output Day 4, 9 pull ups https://code.sololearn.com/cY5JO78lf4OG/?ref=app

29th Oct 2020, 7:33 PM
Alejandra b
Alejandra b - avatar
9 Réponses
+ 10
needed change: print(file.readlines()[n])
29th Oct 2020, 7:44 PM
Szwendacz
Szwendacz - avatar
+ 5
file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here output = file.readlines()[n] output = output.replace("\n", "") print(output) file.close()
12th Jul 2021, 10:31 AM
Constantine Tvalashvili
Constantine Tvalashvili - avatar
+ 1
correct code file = open("/usercode/files/pull_ups.txt",'r') n = int(input()) n >= 0 print(file.readlines()[n]) file.close()
18th Jul 2021, 1:03 AM
Hugues Rodrigue Tha Andela
Hugues Rodrigue Tha Andela - avatar
0
I didn't do it the way the others did it, but there is another way to do it. file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here def pupvalfind(n): a=0 puval="" while True: a+=1 pupval=file.readline() if(a==n+1): return(pupval) break else: continue print(pupvalfind(n)) file.close()
24th Jul 2021, 8:51 AM
Aynur Sunagatullin
Aynur Sunagatullin - avatar
0
# Full answer file = open("/usercode/files/pull_ups.txt") n = int(input()) print(file.readlines()[n]) file.close()
26th Feb 2022, 2:49 AM
Jake Ambrose
Jake Ambrose - avatar
0
file = open ("/usercode/files/pull_ups.txt") b = int(input()) a = file.readlines() for b in a: print(a) file.close it would tell you how many values in the file
16th Apr 2022, 10:06 AM
Y MOHAMMED IQBAL
Y MOHAMMED IQBAL - avatar
0
file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here output = file.readlines()[n] output = output.replace("\n", "") print(output) file.close()
17th May 2022, 2:00 PM
Najwan Najmussabah
0
Right answer is : file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here output = file.readlines()[n] output = output.replace("\n", "") print(output) file.close()
7th Feb 2023, 3:26 AM
Manhar Hadiyal
Manhar Hadiyal - avatar
- 1
file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here print(file.readlines()[n]+"\n") file.close()
30th Jun 2022, 7:28 AM
Chung Lê Đồng
Chung Lê Đồng - avatar