Explanation needed | Sololearn: Learn to code for FREE!

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

2/17/2020 7:55:34 PM

Alisher Berdibekov

+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