Is there a way to format a list from an manual input? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Is there a way to format a list from an manual input?

Dear fellow learners, I currently go through the string formatting module in the more types chapter in python3. I wanted to find a way to be able to choose which list should be formatted. This is what i came up with: # string formatting nums = [4, 5, 6] sq = [16,25,36,49] x=input("choose a list \n") msg = "Numbers: {0} {1}". format(x[0], x[1]) print(msg) The output will turn out the first two letters of the list (or any other str) that I select. Any ideas? I'm still a beginner, but I am grateful for any suggestion you can provide. Thank you

3rd Sep 2018, 8:30 AM
Joseph.Atzinger
1 Resposta
+ 2
you could use an if statement: x = input() if x == "nums": msg = ...... elif x == "sq": msg =.... else: print("choose between msg and sq")
3rd Sep 2018, 8:36 AM
davy hermans
davy hermans - avatar