How to convert these programs to Python?

11 Antworten [Letzter Beitrag]
ssdclickofdeath
Offline
Beigetreten: 05/18/2013

Using a proprietary BASIC IDE/Compiler, JustBASIC, I have written a few simple programs.

None of these programs are particularly important, but I want to know how to port them.

I released them all into the Public Domain with CC0, as they are too short to bother to GPL. (The average is about 35 lines of code.)

Here is a program named 'Eject Joke'.
http://anonnymouse.pastebay.com/1309927

'All About Division'
http://anonnymouse.pastebay.com/1310809

'Computer Chatter'
http://anonnymouse.pastebay.com/1309922

'Fake Installer'
http://anonnymouse.pastebay.com/1309921

ssdclickofdeath
Offline
Beigetreten: 05/18/2013

Correction: "Using a proprietary BASIC IDE/Compiler, JustBASIC, I have written a few simple programs," before I switched to Free Software.

Correction: "None of these programs are particularly important, but I want to know how to port them" to Python.

fbit

I am a member!

Offline
Beigetreten: 07/07/2013

This free book is interesting:

http://openbookproject.net/thinkcs/python/english3e/

It teaches you Python and also systematic program design as far as I remember.

onpon4
Offline
Beigetreten: 05/30/2012

Rewrite them. Look at the code, and write similar code in Python. There is no magical converter tool from BASIC to Python that I'm aware of.

ssdclickofdeath
Offline
Beigetreten: 05/18/2013

I don't know Python. (yet.) These programs are quite simple, so they shouldn't be too hard for me to port, but I don't know the equivalent of input and gosub, and other commands like that.

onpon4
Offline
Beigetreten: 05/30/2012

Python is pretty easy. In Python 3 (what you ought to use; Python 2 is being phased out), you print with the print function (e.g. ``print("Hello, world!")``) and get text input with the input function (e.g. ``a = input("What's your name? ")``). I don't know what gosub does, so I'm not sure what the equivalent Python statement or function would be. As an aside, there's no such thing as a goto in Python, so your use of that would have to be replaced with while loops or for loops.

The Python documentation is available at docs.python.org. You can usually get help at the #python IRC channel on Freenode.

ssdclickofdeath
Offline
Beigetreten: 05/18/2013

gosub means "go to subroutine."
I don't remember what the difference between gosub and goto is, though.

onpon4
Offline
Beigetreten: 05/30/2012

Looks like some sort of a function. Just define functions in Python. The keyword for defining functions is "def"; look at the docs for more specific details.

ssdclickofdeath
Offline
Beigetreten: 05/18/2013

What program do you use (onpon4) for writing Python code?

onpon4
Offline
Beigetreten: 05/30/2012

IDLE is the basic native IDE (sudo apt-get install idle3). gedit will work just fine as well. If you're more into larger IDEs than basic ones and text editors, probably Eclipse.

ssdclickofdeath
Offline
Beigetreten: 05/18/2013

I find that gedit works quite well.

jbar
Offline
Beigetreten: 01/22/2011

If you have previous programming skills, 'dive into python' [1] is a very good starting point to learn python.

To write python code you can use editors like gedit or geany or complete IDE's like eclipse + pydev [2], eric [3], etc.

[1] http://www.diveintopython3.net/
[2] http://pydev.org/
[3] http://eric-ide.python-projects.org/