在 python 中,如果我想让某人以美元输入贷款金额,我可以编写如下代码:
# Loan amount
L = float(input("Enter the loan amount: $"))
Run Code Online (Sandbox Code Playgroud)
但如果我想要的话,比如说利率,它是一个百分比。如果我编码:
# Interest rate
I = float(input("Enter the interest rate: "))
Run Code Online (Sandbox Code Playgroud)
我怎样才能让百分号 % 在他们输入的内容后显示出来?
您需要的是控制终端的光标。
用户输入并按 Enter 键后,光标移动到下一行。
您需要将光标向上移动一行,然后将其移动到该行的末尾,打印 % 然后将光标移回新行。
您可以使用终端的转义序列来做到这一点。
该库可以让您更轻松地执行光标移动
http://code.activestate.com/recipes/475116-using-terminfo-for-portable-color-output-cursor-co/
| 归档时间: |
|
| 查看次数: |
4277 次 |
| 最近记录: |