Nov-16-2021, 10:26 PM
(This post was last modified: Nov-17-2021, 06:29 AM by Cicada3301.
Edit Reason: BBC code
)
Hello there!
I am a complete beginner when it comes in Python...
So..I have a .txt file which contains data of numerous mountains lin this form:
name1 height1 location1 (height1>height2>height3 etc..)
name2 height2 location2
name3 height3 location3
I am asked to create a program which takes as an input a name (of a mountain) from the user and also prints the data that are associated with it.For example if the input is name 2 then the program should print:
The name2 mountain has a height of height 2 is located in location2 and it is (height1-height2) lower than the mountain name1
My progress so far (If one could actually call it progress):
Ty
I am a complete beginner when it comes in Python...
So..I have a .txt file which contains data of numerous mountains lin this form:
name1 height1 location1 (height1>height2>height3 etc..)
name2 height2 location2
name3 height3 location3
I am asked to create a program which takes as an input a name (of a mountain) from the user and also prints the data that are associated with it.For example if the input is name 2 then the program should print:
The name2 mountain has a height of height 2 is located in location2 and it is (height1-height2) lower than the mountain name1
My progress so far (If one could actually call it progress):
def f(): x = input('For which mountain do you want to learn ? :') with open ( 'mountain3.py' ,'r',encoding = 'utf-8') as f : vouna3= f.read f = f.split(',') for z in f: y = z.split(',',maxsplit = 4) z[0] = x z[1] = height z[2] = location (I have been working for these 10 lines for more than 3 hours :/)One of the problems that i have is how can the program search for the namei (i = 1,2,3,4,5....) mountain in the .txt file and locate it...I am basically trying to create a list with sublists (one sublist is ['name1' ,'height1', 'location']1data of the mountains and if the first element (name of the mountain) of a sublist is x then it also print the rest data...Could somebody provide me with an insight or help me create the program in another way?
Ty
