I am stuck on a problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
18th Dec 2020, 9:15 AM
Pratik Maity
Pratik Maity - avatar
10 Answers
+ 1
Pratik Maity try adding \n to create a new line and instead of readlines use readline
18th Dec 2020, 9:22 AM
Krish
Krish - avatar
+ 1
Pratik Maity bro for day 4 you have alloted 2 and want output 9 how
18th Dec 2020, 9:26 AM
Krish
Krish - avatar
+ 1
try my first answer
18th Dec 2020, 9:31 AM
Krish
Krish - avatar
+ 1
it would work
18th Dec 2020, 9:31 AM
Krish
Krish - avatar
+ 1
It has already the file in the challenge so you dont actually need to create your own list. Try this: day = int(input()) file = open("pull_ups.txt", "r") print(file.readlines()[day]) file.close() - - - - - - - - - - - - - - - - - - - - - #file.readlines() return list which contains each line each element of the list so to access the day you just need and index for it (the input will be your index). For Example: ["Day 0, 9 pull ups", "Day 1, 9 pull ups", "Day 2, 10 pull ups", "Day 3, 8 pull ups"] #This list above is the returned values of the file.readlines() so if the day input is "1" then this will be the output: >>> Day 1, 9 pull ups #I hope this helps. Update me if this still does not work.
18th Dec 2020, 9:34 AM
noteve
noteve - avatar
0
Brother read sample output line (12 & 13)
18th Dec 2020, 9:23 AM
Pratik Maity
Pratik Maity - avatar
0
Sorry, It's my mistake. Now for day 0 I want 9
18th Dec 2020, 9:29 AM
Pratik Maity
Pratik Maity - avatar
0
Yep It's solved, one question if I want to do that same things using for loop is it possible
18th Dec 2020, 9:53 AM
Pratik Maity
Pratik Maity - avatar
0
Yes it is possible but it will be longer and indexing a list is easier than having to iterate all the elements.
18th Dec 2020, 9:55 AM
noteve
noteve - avatar
0
Can you please show me how
18th Dec 2020, 9:56 AM
Pratik Maity
Pratik Maity - avatar