Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Throwing an error
#1
Hey all, This was a past homework assignment that I just wanted to get clarification on in regards to my code.
The program is suppose to roll 2 dice, producing 2 random numbers in which those numbers are used to give a fortune.

# Import Functions

import random

# Declare Functions

def roll():
    roll_1 = random.randrange(1,6)
    roll_2 = random.randrange(1,6)

    total_roll = roll_1 + roll_2
    print("You Roll your First Die :", roll_1)
    print("You Roll your Second Die :", roll_2)
    print("Total Roll :", total_roll)
    return (total_roll)

def future(total_roll):
    if total_roll == 2 or total_roll == 3:
        print("When fear hurts you, conquer it and defeat it!")
    elif total_roll == 4 or total_roll == 5:
        print("You will become great if you believe in yourself.")
    elif total_roll == 6 or total_roll == 7:
        print("You will learn from you mistakes... You will learn alot today.")
    elif total_roll == 8 or total_roll == 9:
        print("A new voyage will fill your life with untold memories.")
    elif total_roll == 10 or total_roll == 11:
        print("Be on the lookout for coming events; They cast their shadows beforehand.")
    else:
        print("Serious trouble will bypass you")
        
# Declare Varibles

# Input

# Process

# Output
roll()
future()
It keeps throwing this error

Error:
Traceback (most recent call last): File "C:\Users\Nevalle\Desktop\Lab10.py", line 43, in <module> future() TypeError: future() missing 1 required positional argument: 'total_roll'
I've tried passing the Variable straight from roll to future, while it does work it still throws this error after the code is ran. I've tried recalling the variable back in the main code with future(total_roll) which still doesn't fix it.

I'm not positive on what I need to correct.

any help is appreciated.
Reply
#2
assign the result of the function roll to a variable and pass that variable to the function future
total_roll = roll()
future(total_roll)
Reply
#3
Hey Yoriz

I greatly appreciate it, I always get stuck here or I forget to do it. So basically when it returns from the roll function I have to assign the results of that function in the main section of code, in order to pass it back to the future function. Correct?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020