Python 3.x 如何在spyder中执行简单的交互式程序?

Python 3.x 如何在spyder中执行简单的交互式程序?,python-3.x,ide,spyder,interactive,Python 3.x,Ide,Spyder,Interactive,我写了一个典型的猜数字游戏: import random secret = random.randint(1, 99) guess = 0 tries = 0 print("Hey you on board! I am the dreadfull pirat Robert, and I have a secret!") print("that is a magic number from 1 to 99. I give you 6 tries.") while guess != secret

我写了一个典型的猜数字游戏:

import random
secret = random.randint(1, 99) 
guess = 0
tries = 0
print("Hey you on board! I am the dreadfull pirat Robert, and I have a 
secret!")
print("that is a magic number from 1 to 99. I give you 6 tries.")
while guess != secret & tries < 6:
    guess = input()
    if guess < secret:
        print("You! Son of a Biscuit Eater! It is too little! YOU Scurvy dog!")
    elif guess > secret:
        print("Yo-ho-ho! It is generous, right? BUT it is still wrong! The 
number is too large, Savvy? Shiver me timbers!")   
    tires = tries + 1
if guess == secret:
    print("Enough! You guessed it! Now you know my secret and I can have a peaceful life. Take my ship, and be new captain")
else:
    print("You are not lucky enough to live! You do not have ties. But before you walk the plank...")
    print("The number was ", secret)
    print("Sorry pal! This number became actually you death punishment. Dead men tell no tales! Yo Ho Ho!")
随机导入
secret=random.randint(1,99)
猜测=0
尝试=0
打印(“嘿,你在船上!我是可怕的海盗罗伯特,我有一个
秘密!)
打印(“这是一个从1到99的神奇数字。我给你6次尝试。”)
猜猜看!=秘密&尝试<6:
猜测=输入()
如果猜测<秘密:
打印(“你!一个吃饼干的人的儿子!它太小了!你这个坏蛋!”
elif guess>秘密:
打印(“哟呵呵!它很大方,对吧?但它仍然是错的
数字太大了,精明?吓我一跳
轮胎=轮胎+1
如果猜测==秘密:
打印(“够了!你猜对了!现在你知道我的秘密,我可以过平静的生活了。带上我的船,成为新船长”)
其他:
打印(“你活得不够幸运!你没有领带。但是在你走木板之前……”)
打印(“号码是”,机密)
打印(“对不起,朋友!这个号码实际上是对你的死刑。死人是不会讲故事的!哟呵呵!”)
然而,spyder执行这一切时没有停止用户输入数字,我只得到以下输出:

嘿,你在船上!我是可怕的海盗罗伯斯,我有一个秘密! 这是一个从1到99的神奇数字。我给你6次机会。 你活得不够幸运!你没有领带。但是在你走木板之前。。。 电话号码是56 对不起,朋友!这个数字实际上成了你的死刑。死人不讲故事!哟呵呵

我试图调用cmd->spyder并在那里执行它(通过复制粘贴),但我遇到了很多错误,如:

打印(“号码是”,机密) 文件“”,第1行 打印(“号码是”,机密)

但是,逐行(至少所有带打印的行)执行此代码不是问题


如何以交互方式执行代码,以便用户给出一个数字,然后游戏继续?

tires=trys+1
中,您的代码有几个问题

其次,guess读取字符串,因此您需要将guess转换为int来进行整数比较,使用类似于
guess=int(guess)
的方法

您之所以看不到这一点,是因为while循环中的条件执行时不是true,请运行
guess!=secret&在解释器中尝试<6
,您将看到条件为false

相反,您应该使用
,因为这是一个逻辑运算符
是一个位逻辑运算符(它们不相同)

while guess!=secret and trys<6:
是您应该替换的适当代码行