Getting in shape python project | Sololearn: Learn to code for FREE!


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()

3/17/2021 10:07:22 PM

Charlie DSC

8 Answers

New Answer


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])


You have: print(newList[i]). Should be: print(new_list[i])


Jerry Hobby thank you very much your code helped me too. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ


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() #######


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.


Thank you.. I guess its true that new programmers are always adding extra code lol


please can you sharare the practice problem to solve ?


my solution: file = open("/usercode/files/pull_ups.txt") n = int(input()) cont =file.readlines() print(cont[n])#your code goes here file.close()