此问题已在此处有答案:
How can I read inputs as numbers?(10个答案)
5天前关闭。
# guessing game using real random numbers
import os
import numpy as np
import time
import random
# r = np.array(\[13, 14, 16, 89, 45, 34, 99, 32, 87, 94, 83, 51, 2, 18, 21\])
# rr = np.random.choice(r)
r = random.randint(1,99)
print("Welcome to the guessing game...")
print(r)
time.sleep(2)
i = 0
while i == 0:
a = input("pick a number between 1-100...")
if a == r:
print("correct")
i += 1
else:
print("wrong")
很明显这只是个简单的猜谜游戏。我先用numpy数组试过,然后用randint
1条答案
按热度按时间envsm3lx1#
您的用户输入将是字符串。你需要把它转换成一个数字。
例如,将工作。但是,当用户键入不是数字的内容时,它会崩溃。