I had problems with a random.randint() code. I got the following error message in my program. I am using python 3.8, and I am not sure why this is happening. Below is what appeared in the terminal.
Traceback (most recent call last):
File "C:\Users\W\Desktop\All.py files\droll.py", line 13, in <module>
roll=random.randint(1,
TypeError: randint() takes 3 positional arguments but 7 were given
Here is my code
import random
def rule():
print ("Roll the die!")
print ("If you get a 1, you lose,")
print ("And if you get a 6, you win.")
print ("Anything inbetween does not count.")
rule()
#Main game loop
while True:
q = input ("Are you ready to roll? (Y/N)").lower().strip()
if q == "y":
roll=random.randint(1,
2,
3,
4,
5,
6)
if (roll == 1):
print ("You got a 1! You lost!")
if (roll == 6):
print ("You got a 6! You won!")
else:
print ("You got a middle roll!")
if q == "n":
print ("That's unfortunate.")
if anyone could help fix this problem, it would be much appreciated. I'm not sure if there is a new way to write random codes, and this has been bugging me for a while, as even the most simple code would not work. I've tried to fix this problem by adding a few more random.randints, and using if and statements, however that would sometimes result in 2 answers, or a blank space. If anyone has an answer, once again, I would much appreciate the help. Thanks
Aucun commentaire:
Enregistrer un commentaire