Python Forum
Can anyone help me there? I have this due tomorrow and I'm stuck with no one to talk - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Can anyone help me there? I have this due tomorrow and I'm stuck with no one to talk (/thread-29519.html)



Can anyone help me there? I have this due tomorrow and I'm stuck with no one to talk - rarefaction - Sep-07-2020

import random
import dice
import array

print(
'''
Petals Around the Rose
----------------------

The name of the game is 'Petals Around the Rose'. The name of the
game is important. The computer will roll five dice and ask you to
guess the score for the roll. The score will always be zero or an
even number. Your mission, should you choose to accept it, is to
work out how the computer calculates the score. If you succeed in
working out the secret and guess correctly five times in a row, you
become a Potentate of the Rose.

'''
)
play = 'y'
diceroll = []
dielist = []
diesum = 0
die = 0
rollcount = 0
while play == 'y':
    play = input("Would you like to play Petals Around the Rose [y|n]?")
    total = 0
    while rollcount < 5:
        die = random.randint(1, 6)
        dielist.insert(rollcount, die)
        if die == 5:
            total = total + 4
        elif die == 3:
            total = total + 2
        rollcount = rollcount + 1
    print(dielist)
    print(total)
    dice.display_dice(dielist)
    guess = input("Please enter your guess for the roll:")
    if guess == total:
        print("Well done! You guessed it!")
    elif guess % 2 == 0:
        print("No sorry, it's ",total ," not ", guess,". The score is always even.")
else:
    if play == 'n':
        print("No worries... another time perhaps... :)")
    else:
        print("Stats")
So.. dice.diplay_dice looks for a list of integers (die1, die2, die3, die4, die5), however my list output does not work with the fuction in dyce.py..

I get this error:
Petals Around the Rose
----------------------
Output:
The name of the game is 'Petals Around the Rose'. The name of the game is important. The computer will roll five dice and ask you to guess the score for the roll. The score will always be zero or an even number. Your mission, should you choose to accept it, is to work out how the computer calculates the score. If you succeed in working out the secret and guess correctly five times in a row, you become a Potentate of the Rose. Would you like to play Petals Around the Rose [y|n]?yWould you like to play Petals Around the Rose [y|n]? [2, 6, 6, 6, 5] 4
Error:
Traceback (most recent call last): File "/Users/rf/Documents/Uni 2020 SP5/COMP1039/Assessment1/stajs010_petals.py", line 48, in <module> dice.display_dice(dielist) TypeError: display_dice() missing 4 required positional arguments: 'die2', 'die3', 'die4', and 'die5'
this is dice.py
def display_dice(die1, die2, die3, die4, die5):

    # list to store die values
    dice = [die1, die2, die3, die4, die5]    
    
    # Display die number to the screen.
    print("\n")
    print(format("", '<5s'), end='')
    for i in range(5):
        print(format("Die " + str(i+1), '<10s'), end='')
    print()

    # Display face value of die to the screen.
    print(format("", '<6s'), end='')
    for i in range(5):
          print(format("[" + str(dice[i]) + "]", '<10s'), end='')
    print("\n")

    # Display the top row of face value to the screen.
    print(format("", '<6s'), end='')
    for i in range(5):
        if dice[i] == 1:
            print(format(" ", '<10s'), end='')
        elif dice[i] == 2 or dice[i] == 3:
            print(format("*", '<10s'), end='')
        elif dice[i] == 4 or dice[i] == 5 or dice[i] == 6:
            print(format("* *", '<10s'), end='')
    print()

    # Display the middle row of face value to the screen.
    print(format("", '<6s'), end='')
    for i in range(5):       
        if dice[i] == 1 or dice[i] == 3 or dice[i] == 5:
           print(format(" *", '<10s'), end='')
        elif dice[i] == 6:
           print(format("* *", '<10s'), end='')
        else:
           print(format(" ", '<10s'), end='')
    print()

    # Display the bottom row of face value to the screen.
    print(format("", '<6s'), end='')
    for i in range(5):
        if dice[i] == 1:
            print(format(" ", '<10s'), end='')
        elif dice[i] == 2 or dice[i] == 3:
            print(format("  *", '<10s'), end='')
        elif dice[i] == 4 or dice[i] == 5 or dice[i] == 6:
            print(format("* *", '<10s'), end='')
    print()
    print("\n\n")
Anyone know why it isn't accepting my list? it does with hardcoded variables.


RE: Can anyone help me there? I have this due tomorrow and I'm stuck with no one to talk - DPaul - Sep-09-2020

I'm not sure why this topic remained unanswered,
maybe the code is somewhat fragmented and line 48 of the error message
seems to refer to some other list.

What strikes me at first sight is that your function:
def display_dice(die1, die2, die3, die4, die5):
expects five arguments.
At one point (line 39) you call this function
with only 1 argument:
dice.display_dice(dielist)
even it it has a million values in it, it's only 1 object.
Paul