TypeError: economico() missing 2 required positional arguments: 'carro' and 'consumo'

Question:

I have an assignment to turn in for the University. I already got the correct result in VS Code with the code below (the idea is to show the car with the lowest consumption):

def entrada_carro():
    carro = []
    for i in range(4):
        carro.append(input("Digite o modelo do carro: "))
    return carro

def entrada_consumo():
    consumo = []
    for i in range(4):
        consumo.append(int(input("Digite o consumo do carro: ")))
    return consumo

def economico(carro, consumo):
    menor = consumo[0]
    for i in range(1,4):
        if consumo[i] < menor:
            menor = consumo[i]
    return carro[consumo.index(menor)]

def main():
    carro = entrada_carro()
    consumo = entrada_consumo()
    print("O carro mais economico é o", economico(carro, consumo))

main()

Although it works. The university platform uses another main() function already, which is as follows (there is a particularity, to send on the platform I cannot have the texts inside the inputs, which does not influence; I just remove those before sending):

def main():
    entrada_carro()
    entrada_consumo()
    print(economico())
    
main()

So, I just need to send all the other three functions.

And the error only occurs when I play this in the validator (the code without the part that the platform already has). Test entries are as follows:

  1. (result must be AUDI): JEEP AUDI BMW JAGUAR 10 6 8 12 2. (result must be UP): CELTA GOL UP KA 10 7 6 9

The result with the error: Error img

The article ahead didn’t help me (only if I didn’t understand if the answer is there): how to resolve missing 2 required positional argument python.

Can anyone help understand please? Thanks in advance!!

I have checked that there are differences between my main() and Uni’s:

Mine (with declared variables):

def main():
    carro = entrada_carro()
    consumo = entrada_consumo()
    print("O carro mais economico é o", economico(carro, consumo))

main()

And theirs (without variables declared):

def main():
    entrada_carro()
    entrada_consumo()
    print(economico())
    
main()

I just don’t understand the implications…

Asked By: soaresnoc

||

Answers:

You’ve defined a function economico(carro, consumo) to require two parameters and that main is trying to call it with zero parameters (economico()).

If you can’t change the main invocation run by your uni’s test harness, you’ll need to change your functions to read and write
consumo and carro as globals instead of return values (ick)…

consumo = []
carro = []


def entrada_carro():
    for i in range(4):
        carro.append(input("Digite o modelo do carro: "))


def entrada_consumo():
    for i in range(4):
        consumo.append(int(input("Digite o consumo do carro: ")))


def economico():
    menor = consumo[0]
    for i in range(1,4):
        if consumo[i] < menor:
            menor = consumo[i]
    return carro[consumo.index(menor)]
Answered By: AKX