0

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...

soaresnoc
  • 3
  • 3
  • You've defined a function `economico(carro, consumo)` to require two parameters and are trying to call it with zero parameters (`economico()`). – AKX Nov 02 '22 at 08:18
  • Some text are in PT-BR: carro = car consumo = consumption entrada = input "O carro mais economico é o" = "The most economic car is" "Digite o modelo do carro: " = "Type the car model: " "Digite o consumo do carro: " = "Type car's consumption" – soaresnoc Nov 02 '22 at 08:19
  • Mmm, I see @AKX... but that bit is from Uni's code, so how would I be able to not define in that manner and still make it work? (because I cannot change their main() function)... Do you have ideas? – soaresnoc Nov 02 '22 at 08:21
  • After refreshing the page I saw your answer hahaha; much appreciated, bro! You rock! I have around 3+ min until able to accept your answer (not sure why), then I'll do so! All the best!! – soaresnoc Nov 02 '22 at 08:29

1 Answers1

0

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)]
AKX
  • 152,115
  • 15
  • 115
  • 172