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

17th Feb 2020, 7:55 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  (num1, num2) Now, operation is the second element of operation, which is subtract. So operation returns subtract. The line now is effectively math = subtract(num1, num2) which is the function call for subtract() with the arguments 'num1' and 'num2'.
17th Feb 2020, 8:49 PM
Russ + 1
No problem
17th Feb 2020, 9:00 PM
Russ 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
17th Feb 2020, 8:03 PM
Alisher Berdibekov 0
god. it’s still quite hard, but you made it easier, thank you very much
17th Feb 2020, 8:56 PM
Alisher Berdibekov 