Friday, March 24, 2017

Print("Hello World")

      This week, I've finally started to learn Python! Learning the Python programming language has been always something I wanted to do, but I never got around to actually do it. I've tried before, getting halfway through the first chapter of my python programming book until I started to move into a new house. In between my move and when I started this 20-time project, I experimented with programming Ti-BASIC on my Ti-84 plus. Soon after the move, I got my Apple //e, a 33 year old vintage computer, which I began to learn how to program in it's native built-in language, Applesoft BASIC (a variant of Microsoft BASIC), and I managed to create part of a Brickout/Pong clone. And now I'm here learning to program in Python on modern machines.

       At first glance, Python looks a lot like BASIC. It has similar operators, (functions that act like miniature programs) like print, or input, and appears to have a familiar syntax when viewed from a distance. And this makes sense; Python was created in the early 90's, when BASIC still reigned supreme among beginner programming languages. But Python is way more different than BASIC. For example, here's the common "Hello World" program written in Ti-BASIC, Applesoft BASIC, and Python:

Ti-BASIC:                         Applesoft BASIC:                             Python:
:Disp "Hello World"         10 PRINT "HELLO WORLD"          print("Hello World")

       Notice the difference between Ti-BASIC, Applesoft BASIC, and Python. Applesoft and Ti-BASIC are essentially the same except for a few slight differences (mostly the Ti-84's use of the equivalent to the print command, "Disp", and Applesoft's program line numbering system (the "10")). Python also appears to be the same, but don't let looks deceive you; it isn't. First of all, Python's operators need to be in lowercase in order to work, unlike the BASIC variants. Ti-BASIC's operators are their own characters, so you do not even need to spell them out, and operators entered into Applesoft will automatically be converted to uppercase. Python also needs it's arguments (the values needed for the operators to function) in some statements to be surrounded by parenthesis's, while Basic only needs quotations.

      It might seem that Python is a bit more complicated and obtuse compared to BASIC, but Python is a powerful modern programming language. Just look at the degree of modification that Python's print function allows. By inserting special escape sequences (special characters that can perform different tasks) you can easily make big changes in how a print statement is executed. For example, placing /n in a statement creates a new line prior to the following string of text. BASIC would require a blank print statement to do the exact same thing.

    For a more comprehensive comparison, here's the "Silly Strings" program from my programming book written in Python (Ignore the excessive use of the + operator. This program was originally made to demonstrate that operator and the ability to repeat a statement):

Python:
#Silly Strings
#Demonstrates string concatenation and repetition

print("You can concatenate two" + " strings with the '+' operator.")

#Concatenation Demonstration
print("\nThis string " + "may not " + "seem terr" + "ibly impressive."\
      + " But what"+ "you don't know" + " is that\n" + "it's one real" \
      + "l" + "y" + " long string, created from the concatenation " \
      +"of " + "twenty-two\n" + "different strings, broken across " \
      + "six lines." + " Now are you" + " impressed? " + " " + "Okay,\n" \
      + "this " + "one " + "long" + " string is now over!")
#RIP Fingers. This keyboard sucks.

#Statement Repeat Demonstration
print("\nIf you really like a string, you can repeat it. For example,")
print("who doesn't like pie? That's right, nobody. But if really")
print("like it, you should say it like you mean it:")
print("Pie" *10)

input("Press enter to exit")

Running in the Windows Command Line:

And now the equivalent program in Applesoft Basic:

10 PRINT "You can concatenate two strings with the '+' operator."
20 PRINT " "
30 PRINT "This string may not seem terribly impressive, but what you don't know is that it's one really long string, created from the concatenation of twenty-two different strings, broken across six lines.
40 PRINT "Now are you impressed? Okay, this one long string is over!"
50 PRINT "If you really like a string, you can repeat it. For example, who doesn't like pie? That's right, nobody. But if you really like it, you should say it like you mean it:"
60 For I=1 to 10
70 Print "Pie"
80 Next I

Running in a apple // emulator in 80 column mode:

It may seem that the python version is a lot longer and cryptic than BASIC, but it is anything but that. Notice the / escape sequence in the concatenation demonstration. Python allows you to continue an entire string (a series of text) of a single statement on multiple lines. Applesoft doesn't have the ability to do that, so you have to either make multiple print statements or put it all into one single long print statement, and hope that don't reach the max character limit imposed by software bugs. It also cannot create new lines mid-argument, which would again need another print function. Python also allows programmers to repeat a statement multiple times on the fly by adding "*10". Meanwhile, BASIC needs 3 more lines of code for a For Next function in order to create a loop that repeats the word "Pie" 10 times. Even the Bell Character (a character that induces the computer to beep) is simpler in python. In Applesoft, you need to address a specific memory register in the computer to create the bell character in code, but Python only needs /a. Good luck trying to do this type of stuff on a Ti-84.

All in all, I'm impressed by Python. It seems to be even more powerful than and as intuitive as BASIC. The modability of it is unique and expansive, and given that it is a modern programming language, it can be used anywhere. I think I'm going to really like Python!





*Updated: Added emulator photos, fixed grammatical errors, and made some adjustments.

Apple //jse Emulator by Will Scullen 

Bibliography:
Python Programming for the absolute beginner, Third Edition by Michael Dawson
Applesoft Basic Programming Reference Manual (1978) published by Apple Computer Inc.

Friday, March 17, 2017

A Excuse for Peoria

Hello.

Now this would have been a post about what 20-time and Python is, but I have 36 minutes until I have to post this, so I'm not going to have good grammar. I have been working for the last 2.9 days at the FIRST Robotics Competition in Peoria, Illinois for Blaze Robotics team 3184, our high school's robotics team. Tonight we are freaking out. We have somehow placed in the top 10 teams after today's qualifying matches, and can be picked to compete further if we win most of our games tomorrow. Problem is, some of our systems aren't fully functioning, but our competitors are fully functional. So we have a very slim but real chance of making it. I'm currently sitting in the lobby of the hotel, filled with a dwindling amount of Blaze Robotics members. A member from Trident robotics is talking to the drive team member right next to me, two senior mentors, another teammate, and the team captain, are lounging on the couch across from me, discussing strategy. To the front-right of me, 2 other members are definitely doing something, and the two hotel employees at the front desk are gossiping and being bothered by some guy from another team asking questions. A coffee table in front of me, covered in modified rope, intelligence papers on other teams performances in the qualifying matches, Mtn. Dew, power cords and cookies.  I'm also typing on my main laptop, rather than the pathetic Chromebooks the schools providing us. I'm also very tired, and so is everyone else.

Did I get you to imagine a scene that has nothing to do with 20-time or Python? Yes?
Then welcome to the 20 time python blog.