Write a Python program to calculate an electricity bill: first 50 units Rs 0.50, next 100 units Rs 0.75, next 100 units Rs 1.25, above 250 units Rs 1.50, plus a 17% surcharge.
Input
350
Output
438.75
90.67
Approach
Walk through the slabs with a loop, charging the units that fall in each one.
Upper half: keep a counter that increases across rows of length 1 to 5.
Lower half: continue from 14 counting down, rows of length 4 to 1.
Solution
Python
n=5num=1forrowinrange(1,n+1):print(" ".join(f"{num+i:2}"foriinrange(row)))num+=rownum-=2# last printed was 15, continue from 14forrowinrange(n-1,0,-1):print(" ".join(f"{num-i:2}"foriinrange(row)))num-=row