Heating program to translate from Basic to Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Heating program to translate from Basic to Python (/thread-17820.html) Pages:
1
2
|
Heating program to translate from Basic to Python - tommy2k19 - Apr-25-2019 I have written a few programs in Python but have not done much program translation. My friend asked me to translate his heating program from Basic to Python. Is there an easy way to do this? I haven't tried anything yet? Tha Basic code is below: 1:PRINT"HLOSS85.1":PRINT"":GOTO 3 3:"N"INPUT"INPUT NOTES> ";B$(0):PRINT B$(0):GOTO 3 4:PRINT "":IF L>0 END 5:GOSUB 9:GOTO 104 9:PRINT"------------------------":RETURN 10:"=" PRINT=LPRINT:PRINT"":END 20"L"PRINT=PRINT:PAUSE "PO":END 50:"S" CLEAR:USING 60:DIM B$(0)*24 70:DIM S(6),W(6),G(6),V(0),Z(0),P(0),Q(0),O(0),K(0),N(0):N=1:A(27)=25:R=25:T=600 80:M=21:J=-4:U=5.6:A(30)=55:A(32)=3:GOSUB 9:GOTO 1 104:INPUT"INPUT OUTSIDE TEMP C ";J 105:PRINT"OUTSIDE TEMP ";J;" C 106:INPUT"INPUT ROOM TEMP C ";M 107:C=M-J 108:PRINT"PRINT TEMP ";M;" C":PRINT"TD = ";C;" C 114: GOSUB 9 115:"C"B$(0)="":INPUT"INPUT ROOM NAME ";B$(0) 116:IF B$(0)="" GOTO 115 117:IF B$(0)="*" GOTO 320 120:PRINT B$(0) 125:Y$="N":INPUT"SAME AS LAST ROOM? ";Y$;:IF Y$="Y" GOTO 252 130:S(5)=0:P=0:Q=0:B=0:O=0:K=0k:V=0:O(0)=0:K(0)=0:A=0:G(5)=0:W=0 140:USING:L=0:W=0:H=0:INPUT"INPUT ROOM LENGTH M ";L,"INPUT WIDTH M ";W,"INPUT HEIGHT M ";H 165:Z=LW:V=ZH:IF V=0 GOTO 140 175:PRINT"L=";L;"M W=";W;"M H=";H;"M 176:PRINT"AREA ";Z;" M2 177:PRINT"VOLUME ";V; M3 180:S=1 190:S(S)=LH:GOSUB 500 200:S(S)=WH:GOSUB 500 210:S(S)=S(1):GOSUB 500 220:S(S)=S(2):GOSUB 500 230:S(S)=LW:GOSUB 500 240:S(S)=S(5):GOSUB 500 245:USING:D=M-J:INPUT"INPUT AC/HR ";N;"INPUT TD C ";D 246:PRINT N;" A/C @ ";D;" C TD":B=.33VND 247:INPUT"INPUT SAFETY % ";A(33) 248:IF A(33)>100 GOTO 247 249:A(36)=INT B+INT P+INT Q 250:A(34)=INT((A(33)/100)*A(36)) 251:PRINT"SAFETY ";A(33);"% ";INT A(34);"W 252:K=INT A(34)+INT A(36) 253:Y$="":INPUT"IS INFO CORRECT ? ";Y$ 254:IF Y$="N" GOTO 115 255:IF Y$<>"Y" GOTO 253 256:Z(0)=S(5)+Z(0):P(0)=INT P+P(0):Q(0)=INT Q+Q(0):V(0)=INT B+V(0);O(0)=O+O(0) 257:N(0)=V+N(0):K(0)+K+K(0):A(35)=A(34)+A(35) 258:PRINT"- ROOM HEAT LOSS - 260:PRINT"FABRIC ";INT Q;"W":PRINT"WINDOW ";INT P;"W":PRINT" VENT ";INT B;"W 261:PRINT"SAFETY ";INT A(34);"W 262:PRINT"TOTAL ROOM LOSS ";K;"W 263:IF V=0 GOTO 265 264:PRINT INT ((K/V)+.5);" W/M3 265:GOSUB 9 266:"H"USING:INPUT"INPUT RADIATOR HT MM ";T 267:PRINT"RAD HEIGHT ";T;"MM 268:PRINT"SINGLE ";INT(544K/T);"MM LENGTH 269:PRINT"DOUBLE ";INT(362/T);"MM 270:GOSUB 9 310:GOTO 115 320:PRINT" 330:"G"USING:PRINT:PRINT"-------- TOTALS -------- 350:PRINT"FLOOR AREA ";Z(0);" M2 355:PRINT"VOLUME ";N(0);" M3 410:PRINT"FABRIC LOSS ";INT Q(0);"W 420:PRINT"WINDOW LOSS ";INT P(0);"W 430:PRINT"VENT LOSS ";INT V(0);"W 440:PRINT"SAFETY LOSS ";INT A(35);"W 457:GOSUB 9 460;K=INT Q(0)+INT P(0)+INT V(0)+ INT A(35):PRINT "TOTAL LOSS ";INT K;"W 465:PRINT"AV.HEAT LOSS ";INT((K/M-J))+.5);"W/C 467:IF N(0)=0 GOTO 480 468:PRINT" ";INT((K/N(0)))+.5);"W/M3 470:PRINT USING"###.##";"G VALUE ";(K/(M-J))/N(0);" W/M3/C 480:USING:GOSUB 9 484:GOTO 900 489:A(31)=K+A(29)*1E3 490:INPUT"INPUT BOILER MARGIN % ";A(27) 491:A(28)=A(31)*A(27)/1E2 492:PRINT"BOILER MARGIN":PRINT A(27);"% = ";INT A(28);"W 493:GOSUB 9 494:PRINT" BOILER SIZE 495:PRINT USING"#######.#";" ";(A(31)+A(28))/1E3;"KW 496:USING:GOSUB 9 497:PRINT "":PRINT" 498:END 500:IF S<5 PRINT"WALL ";S 502:IF S=5 PRINT"CEILING/ROOF 504:IF S=6 PRINT"FLOOR 505:X=0:G(S)=0:C=M-J 507:INPUT"INPUT FABRIC U VALUE ";X:GOTO 509 508:GOTO 515 509:INPUT"INPUT TD C";C 510:GOSUB 700 512:IF X>0 GOTO 530 515:PRINT"NO LOSS 530:S=S+1:RETURN 700:IF S<6 INPUT"INPUT GLASS AREA M2 ";G(S) 702:IF G(S)>S(S) GOTO 700 705:W(S)=S(S)-G(S):IF W(S)=S(S) GOTO 710 707:IF S<5 LET A=A+S(S) 710:F=W(S)CX:PRINT W(S);"X";X;"X";C;"=";F;"W 712:Q=Q+F 715:IF S(S)=W(S) RETURN 717:INPUT"INPUT GLASS U VALUE ";U 800:IF S=5 PRINT"ROOFLIGHT":GOTO 805 802:PRINT"WINDOW ";S 805:G=G(S)UC 810:PRINT G(S);"X";U;"X";C;"=";G;"W 815:P=P+G:O=O+G(S) 820:K(0)=G(5) 830:RETURN 900:"D"USING:PRINT"D.H.WATER":INPUT"INPUT NO.OF PEOPLE ";I 905:IF I>0 PRINT 920 910:A(29)=0:PRINT"NONE":GOTO 489 920:INPUT"INPUT LITRE/PERSON ";R 930:PRINT I;"PEOPLE X ";R;"LITRE 940:INPUT"INPUT WARMUP - HRS ";A(32) 942:INPUT"INPUT WATER TD C ";A(30) 945:A(29)=4.2A(A30)IR/3600A(32) 950:PRINT A(32);"HR WARMUP @ ";A(30);"C TD 955:PRINT USING"#####.#";HOT WATER CYL";A(29);"KW 970:USING:GOTO 489 975:"X"USING:INPUT"INPUT FLOOR AREA M2";Z(0):PRINT Z(0) 976:INPUT"INPUT VOLUME M3 ";N(0):PRINT N(0) 977:INPUT"INPUT FABRIC W ";Q(0):PRINT Q(0) 978:INPUT"INPUT WINDOW W ";P(0):PRINT P(0) 979:INPUT"INPUT VENT W "V(0):PRINT V(0) 980:INPUT"INPUT SAFETY W ";A(35):PRINT A(35) 995:GOTO "G" 997:"Z"INPUT"INPUT W";K:PRINT K;"W 998:GOTO "H" RE: Heating program to translate from Basic to Python - Gribouillis - Apr-25-2019 I would start with the GOSUB statements which will become function calls in python. Here you have GOSUB 9, GOSUB 500, GOSUB 700. Looking at the code and the RETURN statements, you see that you can make three functions, one with line 9 alone, and the two others with lines 500-530 and 700-830. Then you need to write logical loops to eliminate the GOTO statements. The rest should be easy. RE: Heating program to translate from Basic to Python - tommy2k19 - Apr-25-2019 (Apr-25-2019, 09:42 AM)Gribouillis Wrote: I would start with the GOSUB statements which will become function calls in python. Here you have GOSUB 9, GOSUB 500, GOSUB 700. Looking at the code and the RETURN statements, you see that you can make three functions, one with line 9 alone, and the two others with lines 500-530 and 700-830. Then you need to write logical loops to eliminate the GOTO statements. The rest should be easy. Thankyou; I'm not asking you to rewrite the code for me, but could you give me a clue (as well as the ones you have given above)? I have a feeling I may get stuck! RE: Heating program to translate from Basic to Python - buran - Apr-25-2019 (Apr-25-2019, 10:02 AM)tommy2k19 Wrote: I have a feeling I may get stuck!Start coding and if/when you get stuck - ask question here RE: Heating program to translate from Basic to Python - tommy2k19 - Apr-25-2019 (Apr-25-2019, 10:04 AM)buran Wrote:(Apr-25-2019, 10:02 AM)tommy2k19 Wrote: I have a feeling I may get stuck!Start coding and if/when you get stuck - ask question here Thankyou - I guess that's the best way to learn! RE: Heating program to translate from Basic to Python - tommy2k19 - Apr-26-2019 (Apr-25-2019, 10:02 AM)tommy2k19 Wrote:(Apr-25-2019, 09:42 AM)Gribouillis Wrote: I would start with the GOSUB statements which will become function calls in python. Here you have GOSUB 9, GOSUB 500, GOSUB 700. Looking at the code and the RETURN statements, you see that you can make three functions, one with line 9 alone, and the two others with lines 500-530 and 700-830. Then you need to write logical loops to eliminate the GOTO statements. The rest should be easy. I have got stuck before I even start coding! I think, as I have just started to learn Python, this may be too much for me! However, I am not the kind of person that gives up. I found this as well: https://www.element14.com/community/thread/32405/l/what-is-equivalent-command-for-gosub?displayFullThread=true (Apr-25-2019, 10:04 AM)buran Wrote:(Apr-25-2019, 10:02 AM)tommy2k19 Wrote: I have a feeling I may get stuck!Start coding and if/when you get stuck - ask question here Is it possible for you to start me off? RE: Heating program to translate from Basic to Python - tommy2k19 - Apr-29-2019 (Apr-25-2019, 09:42 AM)Gribouillis Wrote: I would start with the GOSUB statements which will become function calls in python. Here you have GOSUB 9, GOSUB 500, GOSUB 700. Looking at the code and the RETURN statements, you see that you can make three functions, one with line 9 alone, and the two others with lines 500-530 and 700-830. Then you need to write logical loops to eliminate the GOTO statements. The rest should be easy. I am really having trouble here. Could you give me a clue with the first function please? RE: Heating program to translate from Basic to Python - tommy2k19 - May-01-2019 This is the code I have got so far (which doesn't look right somehow!): print "HL0SS85.1":print"":goto(6) def goto(5): global 6 line = lineNumber lineNumber = 6 RE: Heating program to translate from Basic to Python - tommy2k19 - May-02-2019 Anyone? RE: Heating program to translate from Basic to Python - buran - May-02-2019 Don't try to translate it verbatim. You have to understand the algorithm, the program/logic flow and implement it in python. As to your code - it's difficult to say something different in addition to what you already said yourself - it doesn't look right at all. |