Oct-28-2020, 05:31 AM
Problem: Write calculations using functions and get the results. Let's have a look at some examples:
seven(times(five())) # must return 35
This small function is working as expected and returning 7 * 5 as 35 but
seven(times(five())) # must return 35
This small function is working as expected and returning 7 * 5 as 35 but
a = 0 b = 0 sign = '' def op(a, sign ,b): if sign == '*': return a * b print(op(5, '*', 7)) # Working fine with result 35When I am implementing the similar concept in a slightly bigger program, why is it returning None instead of 35?
a = 0 b = 0 sign = '' def op(a, sign, b): print(a, sign, b) if sign == '*': print(a * b) return a * b def seven(fun): global a a = 7 op(a, sign, b) def times(fun): global sign sign = '*' def five(): global b b = 5 print(seven(times(five()))) # expecting 35 but getting NoneAlso, am I not using the global keyword properly?