Convert python to basic

A while ago I wrote a python program to convert temperature, my current project is to convert this program in to BASIC using Gordon Hendersons return to basic software.

 

My python program can be found on github at https://github.com/zleap/converters I have put the listings below

import sys
import os
 def        clear():
        os.system(‘clear’)
 def exit():
        sys.exit()
def errorfound():
        print (“sorry input empty or not a mumber”)
        exit
print (“This program will ask for a value for Fahrenheit, celcius or kelvin then print these”)
print (“values and their corresponding selected equivelent”)
print(“Menu”)
print(“1. Celcius to Fahrenheit”)
print(“2. Fahrenheit to Celcius”)
print(“3. Celcius to Kelvin”)
print(“4. Kelvin to Celcius”)
print(“5. Kelvin to Farenheit”)
print(“6. Fahrenheit to Kelvin”)
print(“7. Clear screen”)
print(“8. Quit”)
choice = raw_input(“please select (1 – 8): “)
if (len(choice) == 0) or not choice.isdigit():
        print (“sorry input empty or not a mumber”)
        print choice
        exit
#convert c to f
if “1” in choice:
        c = input(“temp in C: “)
        f = c * 9/5 + 32
        print f
#convert f to c
elif “2” in choice:
                f = input(“temp in F: “)
                c = (f – 32) * 5/9
                print c
#convert c to k
elif “3” in choice:
        c = input(“temp in C: “)
        k = c + 273
        print k
#convert k to c
elif “4” in choice:
        k = input(“temp in K: “)
        c = k – 273
        print c
#convert kel to fahrenheit
elif “5” in choice:
        k = input(“temp in K: “)
        f = (k – 273)*1.8 + 32
        print f
#convert fareneit to kelvin
elif “6” in choice:
                f = input(“temp in F: “)
                k = (f – 32) / 1.8 + 273
                print k
#clear screen
elif “7” in choice:
        print(“clear screen”)
        os.system(‘clear’) # on linux / os x
#exit programme
elif “8” in choice:
        exit

 

Now the Return to basic listing

REM temperature conversion
PROC showtitle

PROC showmenu
PROC getinput

ENDPROC

END

vtab = 20
htab = 20

DEF PROC showtitle
PRINT “temperature converter”
PRINT “by Paul Sutton”
PRINT

ENDPROC

DEF PROC showmenu

PRINT “temperature converter”

PRINT
PRINT “MENU”
PRINT “1. C TO F”
PRINT “2. F TO C”
PRINT “3. QUIT PROGRAM”
ENDPROC

DEF PROC getinput

key$ = GET$
IF key$ = “1” THEN PROC ctof
IF key$ = “2” THEN PROC ftoc
IF key$ = “3” THEN PROC quit

ENDPROC

DEF PROC ctof

REM “c to f”

INPUT “TEMP IN DEGREES C: “, C

LET F = C * 9/5 + 32
PRINT F

 

ENDPROC

DEF PROC ftoc

rem “f to c”

INPUT “TEMP IN DEGREES F: “, F

LET C = (F – 32) * 5/9

PRINT C

ENDPROC

DEF PROC quit

stop

endproc

 

So the above is a cut down version of the python program just converting Celcius to Fahrenheit and Farreheit to Celcius.  However it should be easy enough for people to look at the python code and add the other options.

 

references

Return to basic

Python