Seth Thomas
Seth Thomas

Reputation: 11

Passing Variables to Functions in Python - TypeError: Missing Required Positional Arguments

I have read other posts about the topic, but none have seemed to work for me. I'm getting an error:

TypeError: calcs() missing 3 required positional arguments: 'hrs', 'mins', and 'secs'

When I try to pass these three variables into calcs():

The purpose of the code is to see at what degrees are each of the hands on the clock at (relative to 12:00:00).

 def input_io():
    input_time = input("Please enter the time following the HH:MM:SS format - be sure to include all colons and zeros needed. (e.g. 3:45:22 should be input as 03:45:22).")

    bool_okinput = False
    while bool_okinput != True:
        if ':' not in input_time:
            input_time = input("Missing Colon - Please check the format (HH:MM:SS) and re-enter the time.")
        elif len(input_time) != 8:
            input_time = input("Too Many/Too Few Characters - Please check the format (HH:MM:SS) and re-enter the time.")
        else:
            while bool_okinput != True:

                input_time = input_time.split(":")
                hrs = int(input_time[0])
                mins = int(input_time[1])
                secs = int(input_time[2])

                if hrs > 12:
                    input_time = input(
                        "Hours is greater than 12 - Please check the format (HH:MM:SS) and re-enter the time.")
                elif mins > 59:
                    input_time = input(
                        "Minutes is greater than 59 - Please check the format (HH:MM:SS) and re-enter the time.")
                elif secs > 59:
                    input_time = input(
                        "Seconds is greater than 59 - Please check the format (HH:MM:SS) and re-enter the time.")
                else:
                    bool_okinput = True
    return [hrs, mins, secs]

inputs = input_io()
hrs = inputs[0]
mins = inputs[1]
secs = inputs[2]

def calcs(hrs, mins, secs):

    degree_mult = 360/60
    hrs_degree_mult = 360/12

    if hrs == 12:
        hrs = 1

    degrees_secs = (secs * degree_mult)
    degrees_mins = (mins * degree_mult)+(degrees_secs / 60)
    degrees_hrs = (hrs * hrs_degree_mult)+(degrees_mins / 60)+(degrees_secs / (60^2))

    return [degrees_hrs, degrees_mins, degrees_secs]

degrees = calcs()
degrees_hrs = degrees[0]
degrees_mins = degrees[1]
degrees_secs = degrees[2]

print(f"When the Time is: {hrs}:{mins}:{secs}")
print(f"Hour Hand Degrees: {degrees_hrs}")
print(f"Minute Hand Degrees: {degrees_mins}")
print(f"Second Hand Degrees: {degrees_secs}")

Upvotes: 0

Views: 159

Answers (2)

edd
edd

Reputation: 1417

The function signature

def calcs(hrs, mins, secs):

"asks" it is sent 3 arguments when it is called.
The line

degrees = calcs()

calls said function calcs but does not send it any arguments (empty parenthesis). You'd want to send the calculated variables, in the subsequent lines, to the function upon call.

Without giving it all away, here's a hint:

degrees = calcs(already_calculated_1, already_calculated_2, already_calculated_3)

Upvotes: 1

Gabio
Gabio

Reputation: 9494

calcs defined to receive 3 params but you invoke it without any paramater here: degrees = calcs()

Upvotes: 0

Related Questions