0
import random

# Main menu.
print('**** Welcome to the Pick-3, Pick-4 lottery number generator! ****\n\
    \nSelect from the following menu:\n\n1. Generate 3-Digit Lottery number\
    \n2. Generate 4-Digit Lottery number\n3. Exit the Application\n')

# Holds the user's selection in memory.
userInput = int(input())

# If-else statements performs proper operation for the user.
if userInput == 1:
    print('\nYou selected 1. The following 3-digit lottery number was generated:\
        \n\n')
    for i in range(3):
        print(random.randrange(1, 10), end = '')

if userInput == 2:
    print('\nYou selected 2. The following 4-digit lottery number was generated:\
        \n\n')
    for i in range(4):
        print(random.randrange(1, 10), end = '')

if userInput == 3:
    print('\nYou selected 3.\n\nThanks for trying the Lottery Application.\
        \n\n*********************************************************')
    SystemExit

This is the output I get when I enter 1, for example:

You selected 1. The following 3-digit lottery number was generated:

657%

How can I get rid of this percentage sign? I am using VSCode to compile. Thanks.

4

1 回答 1

0

% 不是 Python 的输出。这是您的外壳程序告诉您没有尾随换行符(或者,更确切地说,光标停留在非零列偏移处;当该输出未被捕获或重定向时,您的外壳程序无法看到它运行的程序写入的输出,但它可以查询终端的光标位置)。您退出前的最后一次打印不应该有end=''.

于 2020-05-29T02:04:51.820 回答