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
1 ответ
+ 2
you could use an if statement:
x = input()
if x == "nums":
msg = ......
elif x == "sq":
msg =....
else:
print("choose between msg and sq")