Feb-25-2023, 09:45 PM
I get these PowerPoints based around certain python coding subjects, it gives us a basic tutorial and then gives us prompts to solve. I tried to make the code based around the question below, however I'm obviously doing it wrong and it comes up with the same syntax [Traceback (most recent call last):
File "main.py", line 30, in <module>
RollDice(D,D4,D8,D10,D12,D20)
TypeError: RollDice() takes 1 positional argument but 6 were given], and possible others. If anyone can give me ideas on where I'm going wrong or what I need to change, please let me know as it will be a huge help, Thank You!
Question:
In role playing and board games it is common to have dice with more or less than six sides. D4, D8, D10, D12, D20 are often used.
Write a function that takes one parameter: the number of faces on a dice. The function should return a random roll of the dice.
Code (Still a beginner):
File "main.py", line 30, in <module>
RollDice(D,D4,D8,D10,D12,D20)
TypeError: RollDice() takes 1 positional argument but 6 were given], and possible others. If anyone can give me ideas on where I'm going wrong or what I need to change, please let me know as it will be a huge help, Thank You!
Question:
In role playing and board games it is common to have dice with more or less than six sides. D4, D8, D10, D12, D20 are often used.
Write a function that takes one parameter: the number of faces on a dice. The function should return a random roll of the dice.
Code (Still a beginner):
import random #Subroutine to generate a random number random.seed() D4= int(4) D8 = int(8) D10 = int(10) D12 = int(12) D20 = int(20) #Main Program D=int(input("Please input the dice number you want from the list: 4, 8, 10, 12, 20. ")) def RollDice(D): if D == D4: return random.randint(1,4) print("Rolled a {}".format(Dice)) elif D == D8: return random.randint(1,8) print("Rolled a {}".format(Dice)) elif D == D10: return random.randint(1,10) print("Rolled a {}".format(Dice)) elif D == D12: return random.randint(1,12) print("Rolled a {}".format(Dice)) elif D == D20: return random.randint(1,20) print("Rolled a {}".format(Dice)) else: print("Sorry the AtN you've given hasn't been an element picked from group 1-2 or isn't an element within that group.") Dice = RollDice(D) RollDice(D,D4,D8,D10,D12,D20)