我收到 randit is not a attribute in module random 错误代码

发布于 2025-01-12 04:34:20 字数 995 浏览 1 评论 0原文

每当我输入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黯然#的苍凉 2025-01-19 04:34:20
for letter in "PLEASE LEAVE :)":
    print(letter)
    time.sleep(0.05)
for letter in "PLEASE LEAVE :)":
    print(letter)
    time.sleep(0.05)
过度放纵 2025-01-19 04:34:20

您可以使用 for 循环(请注意,我们需要将它们分成单独的元素,因为最后一个条目有两个字符):

import time
entries = ["P", "L", "E", "A", "S", "E", " ", "L", "E", "A", "V", "E", ":)"]

for entry in entries:
    print(entry)
    time.sleep(0.5)

You can use a for loop (note that we need to separate these out into individual elements, as the last entry has two characters):

import time
entries = ["P", "L", "E", "A", "S", "E", " ", "L", "E", "A", "V", "E", ":)"]

for entry in entries:
    print(entry)
    time.sleep(0.5)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文