我收到 randit is not a attribute in module random 错误代码
每当我输入 rz = random.randit(1, 2) print(rz) 它就可以工作,但是每当我运行此代码时,我都会收到 AttributeError: module 'random' has no attribute 'radint.我做错了什么吗?
import random
user_wins = 0
computer_wins = 0
options = ["rock", "paper", "scissors"]
while True:
user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower()
if user_input == "q":
break
if user_input not in options:
continue
random_number = random.radint(1, 2)
#rock:0, paper:1, scissors: 2
computer_pick = options[random_number]
print("Conputer Picked", computer_pick + ".")
if user_input == "rock" and computer_pick == "scissors":
print("You Won!")
user_wins += 1
elif user_input == "paper" and computer_pick == "rock":
print("You Won!")
user_wins += 1
elif user_input == "scissors" and computer_pick == "paper":
print("You Won!")
user_wins += 1
else:
print("Awww The Computer Won!")
computer_wins +=1
print("希望你玩得开心!")
Whenever i type is rz = random.randit(1, 2) print(rz) it works but whenever i run this code i get the AttributeError: module 'random' has no attribute 'radint. Am i doing something wrong?
import random
user_wins = 0
computer_wins = 0
options = ["rock", "paper", "scissors"]
while True:
user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower()
if user_input == "q":
break
if user_input not in options:
continue
random_number = random.radint(1, 2)
#rock:0, paper:1, scissors: 2
computer_pick = options[random_number]
print("Conputer Picked", computer_pick + ".")
if user_input == "rock" and computer_pick == "scissors":
print("You Won!")
user_wins += 1
elif user_input == "paper" and computer_pick == "rock":
print("You Won!")
user_wins += 1
elif user_input == "scissors" and computer_pick == "paper":
print("You Won!")
user_wins += 1
else:
print("Awww The Computer Won!")
computer_wins +=1
print("Hope You Had Fun!")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
for
循环(请注意,我们需要将它们分成单独的元素,因为最后一个条目有两个字符):You can use a
for
loop (note that we need to separate these out into individual elements, as the last entry has two characters):