如何让VS Code或Sublime完全运行我的python代码?

时间:2017-01-05 03:54:30

标签: python sublimetext visual-studio-code

我制作了一个猜谜游戏程序,但每次我在VS代码或Sublime上运行它时,它只显示第一个输出并挂起。如果我使用Python IDLE它会运行我的整个程序。这是下面的代码:

# This is a guess the number game.
import random

guessesTaken = 0

print('Hello! What is your name?')
myName = input()

number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')

while guessesTaken < 6:
    print('Take a guess.')
    guess = input()
    guess = int(guess)

    guessesTaken = guessesTaken + 1

    if guess < number:
        print('Your guess is too low.') #There are eight spaces in front of print

    if guess > number:   
        print('Your guess is too high.')

    if guess == number:
        break

if guess == number:
    guessTaken = str(guessesTaken)
    print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')

if guess != number:
    number = str(number)
    print('Nope. The number I was thinking of was ' + number)

1 个答案:

答案 0 :(得分:-1)

我有解决问题的方法。 如果你已经下载了sublimeREPL。 转到工具&gt; SublimeREPL&gt; Python&gt; Python - 运行当前文件

如果没有,则复制此包控件:

https://packagecontrol.io/installation

转到视图&gt; show console&gt;并复制上面的链接&gt;单击Enter,完成后关闭sublime并再次打开它。

然后转到&gt;偏好&gt;包控制&gt;并键入&gt; sublimerepl

一旦您下载了,您可以按照上述步骤操作。

希望它有效。