0

Getting in shape python project

This project should read through the imported file and then output the correct output. I think what my code is doing is opening up and reading the imported file and then readlines() puts the data into a list and then I need to loop through the list looking for the correct index file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here new_list = file.readlines() for i in new_list: if n == i: print(newList[i]) file.close()

17th Mar 2021, 10:07 PM
Charlie DSC
Charlie DSC - avatar
9 Answers
+ 6
Here's the working code. Don't need that "for i" loop at all. Just use the input variable (n) as the index into the lines. print(new_list[n])
18th Mar 2021, 12:33 AM
Jerry Hobby
Jerry Hobby - avatar
+ 2
You have: print(newList[i]). Should be: print(new_list[i])
17th Mar 2021, 10:16 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Hi..! the following code works, here the thing is we have to use "readline" or "readlines" ##### file = open("/usercode/files/pull_ups.txt") n = int(input()) #your code goes here for i in range(n): file.readline() print(file.readline()) file.close() #######
11th Jun 2021, 12:54 PM
Ghanta Jeevan Babu
Ghanta Jeevan Babu - avatar
+ 1
Jerry Hobby thank you very much your code helped me too. 🌟🌟🌟🌟🌟
13th May 2021, 3:08 PM
Елена Леващева
Елена Леващева - avatar
0
Thank you.. I fixed my syntax mistake but its still saying no output. This is the project question: 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 Recall the readlines() function that returns a list containing each line in the file as a list item.
17th Mar 2021, 11:27 PM
Charlie DSC
Charlie DSC - avatar
0
Thank you.. I guess its true that new programmers are always adding extra code lol
18th Mar 2021, 1:22 PM
Charlie DSC
Charlie DSC - avatar
0
please can you sharare the practice problem to solve ?
3rd Sep 2021, 8:42 PM
hanane el otmani
hanane el otmani - avatar
0
my solution: file = open("/usercode/files/pull_ups.txt") n = int(input()) cont =file.readlines() print(cont[n])#your code goes here file.close()
26th Oct 2021, 9:13 PM
Edgar Rodas
Edgar Rodas - avatar
0
my solution: file = open("/usercode/files/pull_ups.txt") n = int(input()) print(file.readlines()[n]) file.close()
12th Dec 2021, 12:13 AM
daysweri services