0

# Explanation needed

https://code.sololearn.com/c3NiY3MtCRKY/?ref=app So, basically, I donâ€™t understand a thing after â€śoperationâ€ť string begins and etc. Could someone here make me the analysis, please? I would appreciate it very much

4 Answers

+ 1

operation = [add,subtract,divide,multiply]
options = ["+", "-", "/", "*"]
When the user makes their choice (for this example, they choose "-"), the variable 'user_choice' is defined by options.index(choice). Now, 'choice' here is "-", so options.index("-") is 1. So 'user_choice' is defined as 1.
The line you say you are having trouble understanding is
math = operation [user_choice] (num1, num2)
'user_choice' is 1, so this line becomes
math = operation [1] (num1, num2)
Now, operation[1] is the second element of operation, which is subtract. So operation[1] returns subtract. The line now is effectively
math = subtract(num1, num2)
which is the function call for subtract() with the arguments 'num1' and 'num2'.

+ 1

No problem

0

i get the idea of def, it is easy
but what comes after that - operation, options, choice and most importantly:
math = operation [choice] (num1, num2). I just cannot get why

0

god. itâ€™s still quite hard, but you made it easier, thank you very much

Hot today

Unable to overload +

2 Votes

Hey! [SOLVED]

0 Votes

Pls rectify the errors.

1 Votes

Python list half printed

0 Votes

Find the error please.

0 Votes