Python program to print average of three values using ic()
Python3
from icecream import ic a = 3 b = 11 c = 42 for i in range ( 80 , 83 ): a = a * i b = b * i c = c * i ans = (ic(a) + ic(b) + ic(c)) / 3 ic( int (ans)) |
Output:
$ python gfg.py ic| a: 240 ic| b: 880 ic| c: 3360 ic| int(ans): 1493 ic| a: 19440 ic| b: 71280 ic| c: 272160 ic| int(ans): 120960 ic| a: 1594080 ic| b: 5844960 ic| c: 22317120 ic| int(ans): 9918720
Explanation: Here, ic() is used between the code to print out the values in a structured and simpler method. We are easily able to identify the values of a, b, c and ans in the output.
Debugging with ice cream in Python
Do you often use Python print() to debug your code? However, if you want to make a significant improvement, you could use IceCream which would make debugging faster, cleaner, and easier to read. ic(), which is short for IceCream prints both expressions/variable names and their values. ic() is faster to type than print(). The output is highlighted and printed in a structured format. If you want, you can include program context (filename, line number, and parent function) easily. You could effortlessly debug while solving competitive code problems and save a lot of time while debugging.