mardi 11 février 2020

PYTHON: define function with if -else statement where the input parameter should be a string with letters

I am trying to define a function but it has some assumptions. This is what I got so far:

def payment (order)
if order == ("A"): return (2.00) elif order == ("B"): return (2.50) elif order == ("C"): return (1.50)

BUT: the input parameter "order" should be a string where each letter is either "A", "B", or "C". Also, the function payment should return a float value

Example: payment('AAB') returns 6.50

When I run payment ("B"), my output is 2.0 But when I run payment ("AB"), I got nothing in my output.

How can I solve this? And how can I make the parameter a string?

Many thanks in advance

Aucun commentaire:

Enregistrer un commentaire