0
I am stuck on a problem
can any one help me (https://code.sololearn.com/cjpikTbmEabT/#)
10 Respostas
+ 1
Pratik Maity try adding \n to create a new line
and instead of readlines use readline
+ 1
Pratik Maity
bro for day 4 you have alloted 2 and want output 9 how
+ 1
try my first answer
+ 1
it would work
+ 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.
0
Brother read sample output line (12 & 13)
0
Sorry, It's my mistake. Now for day 0 I want 9
0
Yep It's solved, one question if I want to do that same things using for loop is it possible
0
Yes it is possible but it will be longer and indexing a list is easier than having to iterate all the elements.
0
Can you please show me how