我正在通过创建这个简单的游戏来提高我的python 3技能。
非常基本的,你有1到5之间的随机数,如果你认为它是正确的,你就赢了。但是出于合乎逻辑的原因,每当我尝试运行它时,我得到的就是"你输了#34;结果即使我的测试打印显示我得到相同的数字。
#!/usr/bin/python3
import random
B = input("Pick a number between 1 and 5:" )
F = random.randrange(1, 5, 1)
if B == F:
print("You win")
else:
print("You lose")
print (B, F)
我无法判断导致问题的==
函数或if
函数是否出于某种原因是错误的,但它看起来不是
答案 0 :(得分:3)
import random
B = int(input("Pick a number between 1 and 5 ")) # Input goes inside int()
F = random.randrange(1,5,1)
if B == F:
print("you win")
else:
print("you lose")
print(B, F)
旁注:您生成的代码在Python 2中实际运行正常,input
会在int
返回SELECT t1.col1 AS POSITIVE, t2.col1 AS NEGATIVE
FROM (
SELECT col1
from tableA
WHERE col1 > 0 ) t1
FULL OUTER JOIN (
SELECT col1
FROM tableA
WHERE col1 < 0 ) t2 ON t1.col1 = ABS(t2.col1)
ORDER BY ABS(COALESCE(t1.col1, t2.col1))
。
答案 1 :(得分:1)
投放input
以获得int
#!/usr/bin/python3
import random
B = int(input("Pick a number between 1 and 5 " ))
F =(random.randrange(1,5,1))
if B == F:
print("you win")
else:
print("you lose")
print (B, F)
答案 2 :(得分:0)
B = int(input("Pick a number between 1 and 5 " ))
将输入的类型更改为整数。