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.

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25
  • I tried it (without vscode) and couldn't reproduce the percent sign. I added the "vscode-python" tag because it seems special to this. By the way: The "SystemExit" in last line is useless. – Michael Butscher May 29 '20 at 01:59
  • 1
    I also tried it (with VS Code) for each of the inputs, and I couldn't reproduce the percent symbol either. This looks relevant: https://stackoverflow.com/questions/36270945/percent-sign-at-the-end-of-the-output-of-python-script – Matthew Kligerman May 29 '20 at 02:02
  • Thank you very much @MichaelButscher. I'll be adding a loop to this program. Just got stuck on this problem. – Beau Vansiclen May 29 '20 at 02:04

1 Answers1

0

The % is not output from Python. It's your shell telling you there wasn't a trailing newline (or, rather, that the cursor was left at a nonzero column offset; your shell can't see what output the programs it ran wrote when that output wasn't captured or redirected, but it can query the terminal for cursor position). Your last print before exiting shouldn't have end=''.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441