0

Help me to minimize this python code.

I'm made one program for print all paper size by using only A0 paper size. please help me to make it sort. Please check the code in my profile. # for A0 size ppr a0_lenght=1189 a0_breath=841 print('A0 size=',a0_lenght,'mm x',a0_breath,'mm') # for A1 size ppr max1=max(a0_lenght,a0_breath) a1_lenght=int(a0_breath) a1_breath=int(max1/2) print('A1 size=',a1_lenght,'mm x',a1_breath,'mm') # for A2 size ppr max2=max(a1_lenght,a1_breath) a2_lenght=int(a1_breath) a2_breath=int(max2/2) print('A2 size=',a2_lenght,'mm x',a2_breath,'mm') # for A3 size ppr max3=max(a2_lenght,a2_breath) a3_lenght=int(a2_breath) a3_breath=int(max3/2) print('A3 size=',a3_lenght,'mm x',a3_breath,'mm') # for A4 size ppr max4=max(a3_lenght,a3_breath) a4_lenght=int(a3_breath) a4_breath=int(max4/2) print('A4 size=',a4_lenght,'mm x',a4_breath,'mm') # for A5 size ppr max5=max(a4_lenght,a4_breath) a5_lenght=int(a4_breath) a5_breath=int(max5/2) print('A5 size=',a5_lenght,'mm x',a5_breath,'mm') # for A6 size ppr max6=max(a5_lenght,a5_breath) a6_lenght=int(a5_breath) a6_breath=int(max6/2) print('A6 size=',a6_lenght,'mm x',a6_breath,'mm') # for A7 size ppr max7=max(a6_lenght,a6_breath) a7_lenght=int(a6_breath) a7_breath=int(max7/2) print('A7 size=',a7_lenght,'mm x',a7_breath,'mm') # for A8 size ppr max8=max(a7_lenght,a7_breath) a8_lenght=int(a7_breath) a8_breath=int(max8/2) print('A8 size=',a8_lenght,'mm x',a8_breath,'mm') You can see this code in my profile also.

26th May 2020, 12:18 PM
MOHIT Yede
MOHIT Yede - avatar
2 Respuestas
0
It can be shortened to length=1189 breadth=841 for i in range(0, 8): print('A',i,' size=',length,'mm ×',breadth,'mm') length,breadth = breadth, int(max(length, breadth)/2)
26th May 2020, 1:04 PM
Ore
Ore - avatar
0
To minimize (and for other reasons) you could put the values into a dictionary (see tutorials). The content of a dictionary is easy to sort (see tutorials). Some languages have libraries with utils for that within their standard libraries, in other languages you have to implement a sort algorithm.
26th May 2020, 1:07 PM
Sandra Meyer
Sandra Meyer - avatar