0

What happens with this code?

Output is some unintelligible string of numbers and letters, for example "<function total at 0x71a634dd30d0>" with input of 24 used for simple multiplication. It doesn't get any better with any other input. The code: https://www.sololearn.com/en/compiler-playground/cSqRky5VkXpb

15th May 2024, 8:45 AM
Igor Matić
Igor Matić - avatar
3 odpowiedzi
+ 4
You have a mistake in your code. You're printing the function object and displaying its address in memory. To correct the mistake you have to include the arguments in your code. bill = total(price, count) print(bill)
15th May 2024, 11:15 AM
Chris Coder
Chris Coder - avatar
+ 4
Let me add a little background to Chris Coder's answer. What your code "bill = total" doing is assigning a function to a variable. That is creating an alias of the total() function. If keeping your code unchanged, below lines produce the same result. print(total(price = 10.35, count = 10)) # 103.5 print(bill(price = 10.35, count = 10)) # 103.5
15th May 2024, 12:36 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Try it with this line: bill = total(price, count)
15th May 2024, 10:58 AM
Ausgrindtube
Ausgrindtube - avatar