0

Parametric Python Function

Hi all, I would like to code a parametric input function that can understand which dictionary it has to go to take "input_text" text for dictionary input command at the beginning and can print output from specified dictionary at the end. Can you help me about it ? Thank you! nutrition = {1: "Carnivorous", 2: "Herbivorous", 3: "Omnivorous", 4: "No Information", input_text: """Please Enter Nutrition Type 1. Carnivorous 2. Herbivorous 3. Omnivorous 4. No Information\n"""} respiratory = {1: "with Oxygen", 2: "without Oxygen", 3: "No Information", input_text: """Please Enter Respiratory Type 1. with Oxygen 2. without Oxygen 3. No Information\n"""} y = input(respiratory["input_text"]) if y == "1": selection = respiratory["1"] print(selection) elif y == "2": selection = respiratory["2"] print(selection) elif y == "3": selection = respiratory["3"] print(selection) else: print("WARNING")

19th Apr 2020, 10:12 AM
Gokberk
Gokberk - avatar
2 Antworten
0
U could build a list of dictionaries Mydicts =[ nutrition,respiratory] After choice of fitting dictionary access is Eg Mydicts[0][3]=Omnivorous
19th Apr 2020, 12:40 PM
Oma Falk
Oma Falk - avatar
0
I tried to do that. But couldn't i write some simple dict. can you send me a basic code for your recomendation. numbers = {1:"One",2:"Two",3:"Three",4:"Four", 5:"1.One 2.Two 3.Three 4.Four"} letters = {1:"A",2:"B",3:"C",4:"D",5:"1.A 2.B 3.C 4.D"} code = {1:"!",2:"?",3:"#",4:"&",5:"1.! 2.? 3.# 4.&"}
19th Apr 2020, 4:00 PM
Gokberk
Gokberk - avatar