简体   繁体   English

python 中的新行列表

[英]New line list in python

How can I create a list that starts in a new line because right now my menu looks like this:我如何创建一个以新行开头的列表,因为现在我的菜单如下所示:

Choose index in [(0, 'Display ID'), (1, 'Display Balance'), (2, 'Display Annual Interest Rate'), (3, 'Display Monthly Interest Rate'), (4, 'Display Monthly Interest'), (5, 'Withdraw Money'), (6, 'Deposit Money'), (7, 'Exit')]在[(0, '显示ID'), (1, '显示余额'), (2, '显示年利率'), (3, '显示月利率'), (4, '显示月利率')中选择索引利息'), (5, '取款'), (6, '存款'), (7, '退出')]

and I need it to look like this:我需要它看起来像这样:

Choose index in (0) Display ID在 (0) 显示 ID 中选择索引

(1) Display Balance (1) 显示平衡

(2) Display Annual Interest Rate (2) 显示年利率

(3) Display Monthly Interest Rate (3) 显示月利率

(4) Display Monthly Interest (4) 显示每月利息

(5) Withdraw Money (5) 取款

(6) Deposit Money (6) 存款

(7) Exit (7) 退出

I have tried using '\n'.join but it doesn't work.我曾尝试使用 '\n'.join 但它不起作用。

 actions = ["Display ID",
               "Display Balance",
               "Display Annual Interest Rate",
               "Display Monthly Interest Rate",
               "Display Monthly Interest",
               "Withdraw Money",
               "Deposit Money",
               "Exit"]
        while True:
            choice = int(input("Choose index in " + str(list(enumerate(actions)))))
            apply_actions(choice, acc)

Instead of:代替:

choice = int(input("Choose index in " + str(list(enumerate(actions)))))

Do:做:

print("Choose index in ")
for i, action in enumerate(actions):
    print("(" + str(i) + ") " + action)

Alternatively:或者:

print("Choose index in \n" + "\n".join(["(" + str(i+1) + ") " + action for i, action in enumerate(actions)]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM