Unfortunately this weeks post will a bit like Peoria's and 10k's, in which I pretty much didn't have the time to come up with any new developments in my journey to learn python. I have commitments and a few other class projects I need to address, so 20-time had to be put on the back burner a little bit. Rest assured, there will be new content next week.
One of the big problems of working on this 20-time project is ironically a matter of time. While I do have about 20% of class time to dedicate to my project, it only equates to a measly 48 minutes a week, which is minuscule compared to the hours I normally need to dedicate to this project in order to properly learn important concepts and ultimately write about them. This process spans over at least 2 days, usually Thursday and Friday due to commitments and work that occupies most of the week, with a required weekly blog post published by 12:00 PM on Fridays. This means that when I would post new content, the subject matter is very new to not only you, but myself. I would rather post when I felt that my content was correct and error-free, but that's completely out of my hands. This is the reason why Peoria, 10k, and this post exists.
Anyway's, in some of my spare time, I did manage to mess around with how I learn python by using a site called codecademy, a free website that can teach you how to program in multiple languages, including python. For the most part, codecademy is a good way to rapidly learn python, coupling an interactive hands on experience with dedicated literature to the subject, rather than the hard way of learning through a book, which is what I have been doing. Learning through the book is time consuming and can really only be done through dedicated sessions, as I have to be tied to a computer that can run IDLE, but learning through an online source allows for me to learn anywhere as long as I have a WiFi connection and a device with a usable keyboard. I do have some concerns with it though, especially with learning at a fast pace, which I've learned in the past isn't always a good idea, especially with a topic like programming. You need to understand everything your taking in, as they will become very relevant once you begin to use those skills. I've also had problems with some of the lessons being a bit cryptic, but with some tinkering and exploring their forums, you can eventually get through it. All in all, codecademy is great for reviewing or learning new things. Here is a link if you want to take a look for yourself.
This week didn't bring much to the table. I've so far enjoyed writing this blog, to the point that I may continue doing it towards or after the end of 20-time, so there is a possibility I may talk about different topics and avoid these types of useless posts in future. See you guys next week.
Friday, April 28, 2017
Friday, April 21, 2017
If Then, Else?
Last week I said that mathematical operations were the bread and butter of programming, but now, logical operators have become the jelly that's slapped onto it.
This week, as you could probably guess, I started to learn about logic operators! Logic operators are essentially the if-then or if-else statements commonly seen in the majority of programming languages, and are used to evaluate whether a set of conditions are true within a program. These are significant as it is literally used in every program imaginable, and are the basis for modern computers. They're based on the principals of Boolean Algebra, which is a version of algebra were the values of variables are treated as either the true and/or false. Now this was the jumping off point for my knowledge of Ti-Basic and Applesoft BASIC, so please note that some of this information is iffy as I've never had much experience with them.
Now in python an If-Then statement would look something like this;
potato = input("potato")
if potato == "tomato":
print("potato tomato")
In this statement, if the variable (in if then statements this variable is known as a Sentry Variable) potato is equal to the value tomato, the computer will print the argument "potato tomato". If potato doesn't equate to "tomato", the computer will ignore the statement. If we wanted to, say, have the if-then statement do something if potato isn't "tomato", we can use the else clause:
potato = input("potato")
if potato == "tomato":
print("potato tomato")
else:
print("we need a certain red vegetable")
Now if potato doesn't equate to "tomato", the computer would print "we need a certain red vegetable". If we wanted to have the computer perform actions when potato equates to other values, we can use the elif (else-if) clause:
potato = input("potato")
if potato == "tomato":
print("potato tomato")
elif potato == "tornado":
print("potato tornado")
else:
print("we need a certain red vegetable or storm-spout thing")
With elif, if potato equates to tornado, the computer will print "potato tornado". If potato doesn't exactly equate to "tomato" or "tornado", the else clause will act as a catch-all for any other values.
If-then statements are great for user input for specific variables, like passwords. The only problem is if we mess up by entering "tamato" rather than "tomato", we can't re-input any new values for potato. The solution is to put the program into a loop, in this case a while loop. A while loop is essentially an if-then/else/else-if statement with if replaced by while, causing the program to enter a loop until certain conditions are met. If we wanted a program that will loop until "tomato" is entered by adding the while loop, it would look exactly like this:
potato = " "
while potato != "tomato":
potato = input("we need a certain red vegetable")
print("potato tomato")
The program will now loop until potato is tomato. If potato doesn't equal to tomato, the program will ask the user to enter a different value until tomato is specified. A problem with while loops can occur when the program has a slight flaw in it:
potato = " "
while potato != "tomato":
potato = print("we need a certain red vegetable")
print("potato tomato")
Output:
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
Did you see the problem? In this case, I accidentally typed a print function rather than a input function, inadvertently causing an infinite loop, printing "we need a certain red vegetable" over and over forever until we manually end it.
We can change how the condition of the sentry variable by using different comparison operators. These are the equal to (=), not equal to (≠), greater than (>), less than (<), greater than or equal to (⋝), and finally the less than or equal to (⋜) symbols that everyone fussed over in elementary school, except they are now are expressed as ==, !=, >, <, >=, <= in python respectively.
Among the logic operators, I also learned about how to generate random numbers using the random module (modules, by the way, is essentially code represented by a certain word). By using this module, we gain the randint() and randrange() functions. The randint() function produces random numbers that are between two specified values (so randint(5,10) would produce a number between 5 and 10), while the randrange() function will produce integers from a specified group of numbers, similar to randint(), but will generate any number between the specified number and 1 (so randrange(12) would generate any number between 1 and 12).
The odd thing about modules though, unlike functions, is that they need to be imported in order to be used. They aren't present by default, so they have to be loaded in using an import statement. The functions in modules also need to be called by using Dot notation, which is a fancy way of saying that you need to type the module's name and the functions name with a period in between.
*Updated. Included more information on logic operators, random integer generators and modules. Also fixed grammatical errors.
bibliography:
Python Programming for the absolute beginner, Third Edition by Michael Dawson
This week, as you could probably guess, I started to learn about logic operators! Logic operators are essentially the if-then or if-else statements commonly seen in the majority of programming languages, and are used to evaluate whether a set of conditions are true within a program. These are significant as it is literally used in every program imaginable, and are the basis for modern computers. They're based on the principals of Boolean Algebra, which is a version of algebra were the values of variables are treated as either the true and/or false. Now this was the jumping off point for my knowledge of Ti-Basic and Applesoft BASIC, so please note that some of this information is iffy as I've never had much experience with them.
Now in python an If-Then statement would look something like this;
potato = input("potato")
if potato == "tomato":
print("potato tomato")
In this statement, if the variable (in if then statements this variable is known as a Sentry Variable) potato is equal to the value tomato, the computer will print the argument "potato tomato". If potato doesn't equate to "tomato", the computer will ignore the statement. If we wanted to, say, have the if-then statement do something if potato isn't "tomato", we can use the else clause:
potato = input("potato")
if potato == "tomato":
print("potato tomato")
else:
print("we need a certain red vegetable")
Now if potato doesn't equate to "tomato", the computer would print "we need a certain red vegetable". If we wanted to have the computer perform actions when potato equates to other values, we can use the elif (else-if) clause:
potato = input("potato")
if potato == "tomato":
print("potato tomato")
elif potato == "tornado":
print("potato tornado")
else:
print("we need a certain red vegetable or storm-spout thing")
With elif, if potato equates to tornado, the computer will print "potato tornado". If potato doesn't exactly equate to "tomato" or "tornado", the else clause will act as a catch-all for any other values.
If-then statements are great for user input for specific variables, like passwords. The only problem is if we mess up by entering "tamato" rather than "tomato", we can't re-input any new values for potato. The solution is to put the program into a loop, in this case a while loop. A while loop is essentially an if-then/else/else-if statement with if replaced by while, causing the program to enter a loop until certain conditions are met. If we wanted a program that will loop until "tomato" is entered by adding the while loop, it would look exactly like this:
potato = " "
while potato != "tomato":
potato = input("we need a certain red vegetable")
print("potato tomato")
The program will now loop until potato is tomato. If potato doesn't equal to tomato, the program will ask the user to enter a different value until tomato is specified. A problem with while loops can occur when the program has a slight flaw in it:
potato = " "
while potato != "tomato":
potato = print("we need a certain red vegetable")
print("potato tomato")
Output:
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
we need a certain red vegetable
Did you see the problem? In this case, I accidentally typed a print function rather than a input function, inadvertently causing an infinite loop, printing "we need a certain red vegetable" over and over forever until we manually end it.
We can change how the condition of the sentry variable by using different comparison operators. These are the equal to (=), not equal to (≠), greater than (>), less than (<), greater than or equal to (⋝), and finally the less than or equal to (⋜) symbols that everyone fussed over in elementary school, except they are now are expressed as ==, !=, >, <, >=, <= in python respectively.
Among the logic operators, I also learned about how to generate random numbers using the random module (modules, by the way, is essentially code represented by a certain word). By using this module, we gain the randint() and randrange() functions. The randint() function produces random numbers that are between two specified values (so randint(5,10) would produce a number between 5 and 10), while the randrange() function will produce integers from a specified group of numbers, similar to randint(), but will generate any number between the specified number and 1 (so randrange(12) would generate any number between 1 and 12).
The odd thing about modules though, unlike functions, is that they need to be imported in order to be used. They aren't present by default, so they have to be loaded in using an import statement. The functions in modules also need to be called by using Dot notation, which is a fancy way of saying that you need to type the module's name and the functions name with a period in between.
*Updated. Included more information on logic operators, random integer generators and modules. Also fixed grammatical errors.
bibliography:
Python Programming for the absolute beginner, Third Edition by Michael Dawson
Friday, April 14, 2017
Back in Business with Math and Variables!
For the first time in 3 weeks, I'm typing in Python again! Currently, I've finished chapter 2 of my programming book, which dealt with types, variables, and simple i/o and now I will be going on to chapter 3, which from the title teaches about "Branching, While Loops, and Program Planning". But so far from what I've learned from the past week, is the bread and butter of programming: Mathematics. Specifically how to program simple mathematical equations, such as the x+y=z variety. From my experience of learning Ti-BASIC and Applesoft, this is the point when programming begins to be useful and applicable, as we essentially recreate that tiny calculator that you get in first grade.
First of all we have the "+", "-", "/","//","%", and "*" operators to play around with. Writing an equation using these new operators in python is similar to writing it down and solving it on paper, but now the computer does all the thinking for you. For example, you can type in 5+5 and the computer will calculate the equation and determine that the answer is 10. The only problem is that the computer doesn't tell you the answer; you have to tell it to tell you the answer after it's solved it. This means that you have to use a print function, like you would in BASIC. So, what you end up typing in Print(5+5) and then the computer will give you the answer.
An interesting thing about Python is that there are now Augmented Assignment Operators, which shorten down simple mathematical equations by attaching the "=" sign to the end of an operator . For example, x = x +5 becomes x+=5. This can help shorten and simplify larger equations that may make use of something else I've learned: variables! A variable by the way is a way to label and access information, and these things make programming a lot easier. By assigning a name for a specific value or a series of strings, you can use less space and run your program more efficiently. So if our program from above used variables, it would look something like this:
answer = 5 + 5
print(answer)
Another thing I learned, is that there are 2 different types of math in python and programming in general: integer and floating point. Integers are whole numbers, which do not have a fractional part (numbers like 1, 27, 61, -100, 0, etc), while floating point numbers are numbers with a decimal point (numbers like 2.375, -99.1, 1.0, etc). Both are used for different purposes. Integer is used when we want a nicely rounded answer (the "//" operator is specifically used for this purpose), while floating point is used for accurate "true" answers. We can also convert existing values into Integers, floating points, or simple strings using the "float()", "Int()", and "Str()" functions respectively.
Here's a program that demonstrates everything I've learned so far:
# Challenge Program "Tipper"
# Demonstrates key programming concepts
# Calculates the necessary amount of a purchase for a 15% and 20% Tip
# Nathan Czaja, 4/14/2017
bill = int(input("what is your Bills total?"))
tip15 = bill*0.15
tip20 = bill*0.20
billtip15 = int(bill+tip15)
billtip20 = int(bill+tip20)
print("\a", "Total entered: $", bill, \
"\n15% Tip: $", tip15, \
"\nBill + 15% Tip: $", billtip15, \
"\n\n20% Tip: $", tip20, \
"\nBill + 20% Tip: $", billtip20)
input("\nPress enter to exit")
These new tools are extremely helpful in STEM (Science Technology Engineering and Mathematics) applications, where equations run rampant and constant calculation becomes tiresome. Using Ohms Law (V = I *R) and the quadratic formula ( (-b+/-√(b^2 (4)ac))/2a) over and over agian can be repetitive and strenuous, so being able to use a machine to do the dirty work for you is a godsend, and is one of the reasons why computers came into being in the first place.
First of all we have the "+", "-", "/","//","%", and "*" operators to play around with. Writing an equation using these new operators in python is similar to writing it down and solving it on paper, but now the computer does all the thinking for you. For example, you can type in 5+5 and the computer will calculate the equation and determine that the answer is 10. The only problem is that the computer doesn't tell you the answer; you have to tell it to tell you the answer after it's solved it. This means that you have to use a print function, like you would in BASIC. So, what you end up typing in Print(5+5) and then the computer will give you the answer.
An interesting thing about Python is that there are now Augmented Assignment Operators, which shorten down simple mathematical equations by attaching the "=" sign to the end of an operator . For example, x = x +5 becomes x+=5. This can help shorten and simplify larger equations that may make use of something else I've learned: variables! A variable by the way is a way to label and access information, and these things make programming a lot easier. By assigning a name for a specific value or a series of strings, you can use less space and run your program more efficiently. So if our program from above used variables, it would look something like this:
answer = 5 + 5
print(answer)
Another thing I learned, is that there are 2 different types of math in python and programming in general: integer and floating point. Integers are whole numbers, which do not have a fractional part (numbers like 1, 27, 61, -100, 0, etc), while floating point numbers are numbers with a decimal point (numbers like 2.375, -99.1, 1.0, etc). Both are used for different purposes. Integer is used when we want a nicely rounded answer (the "//" operator is specifically used for this purpose), while floating point is used for accurate "true" answers. We can also convert existing values into Integers, floating points, or simple strings using the "float()", "Int()", and "Str()" functions respectively.
Here's a program that demonstrates everything I've learned so far:
# Challenge Program "Tipper"
# Demonstrates key programming concepts
# Calculates the necessary amount of a purchase for a 15% and 20% Tip
# Nathan Czaja, 4/14/2017
bill = int(input("what is your Bills total?"))
tip15 = bill*0.15
tip20 = bill*0.20
billtip15 = int(bill+tip15)
billtip20 = int(bill+tip20)
print("\a", "Total entered: $", bill, \
"\n15% Tip: $", tip15, \
"\nBill + 15% Tip: $", billtip15, \
"\n\n20% Tip: $", tip20, \
"\nBill + 20% Tip: $", billtip20)
input("\nPress enter to exit")
What this program does is calculate the amount of money needed for a 15% or a 20% tip. The operation of this program is pretty simple. For example, for variable bill, I can enter $200 dollars. The "int()" function turns the value entered into a usable integer, rather than a string that does nothing. Next, it gets multiplied with 15% and 20% to calculate the relative tips. The tips are then added to the price of the bill, to give a total owed. Finally, the next print() function displays the information calculated to the user.
The running program would look something like this:
what is your Bills total?200
Total entered: $ 200
15% Tip: $ 30.0
Bill + 15% Tip: $ 230
20% Tip: $ 40.0
Bill + 20% Tip: $ 240
Press enter to exit
>>>
These new tools are extremely helpful in STEM (Science Technology Engineering and Mathematics) applications, where equations run rampant and constant calculation becomes tiresome. Using Ohms Law (V = I *R) and the quadratic formula ( (-b+/-√(b^2 (4)ac))/2a) over and over agian can be repetitive and strenuous, so being able to use a machine to do the dirty work for you is a godsend, and is one of the reasons why computers came into being in the first place.
Friday, April 7, 2017
An Excuse for 10K
Hello. Normally this would have been about what I've learned about python, but this isn't the case. Since my last post from 2 weeks ago, I have been too busy to really learn anything about python. And this week is a special case. Like my first ever blog post, my 20-time project has been interrupted by a robotics competition, only this time it's on home turf.
The Minnesota 10,000 Lakes Regional, or as it is informally called by everyone as "10k", started on Thursday and at the time of this blog post, is currently ongoing. However for me, it's been going on since Monday night. For 2 days straight, I worked with my robotics team to get our robot up, running, and packed up for 10k. I also helped out on Wednesday night, which sucked up most of my time in the first half of the week. But then came Thursday, the opening day. In order to make up most of our teams time, we rushed out at 7:00 in the morning to get to our pits at Minnesota State University, where 10k was hosted. We began to work on our robot immediately, putting together and testing it in practice matches for nearly 14 hours straight. And then today, Friday, we began to compete in the qualification matches. Now is the time our hard work meant something. I mostly helped with general fabrication, but today I temporarily became part of our drive team, being the guy setting out gears for our robotic to pick up. It was pretty fun! Much better than scouting out matches, which involved logging in every movement of every robot on the field.
Tonight, team 3184 Blaze Robotics has so far managed to get to 15th place, with the possibility of going to quarterfinals tomorrow. I am exhausted from working so much, so I apologize for not having a on topic blog post. I also apologize for the bad grammar, but it's 11:30 and I need to get this done. Next Friday though, I promise that we'll be finally on topic.
*4/21/17 fixed grammatical errors
The Minnesota 10,000 Lakes Regional, or as it is informally called by everyone as "10k", started on Thursday and at the time of this blog post, is currently ongoing. However for me, it's been going on since Monday night. For 2 days straight, I worked with my robotics team to get our robot up, running, and packed up for 10k. I also helped out on Wednesday night, which sucked up most of my time in the first half of the week. But then came Thursday, the opening day. In order to make up most of our teams time, we rushed out at 7:00 in the morning to get to our pits at Minnesota State University, where 10k was hosted. We began to work on our robot immediately, putting together and testing it in practice matches for nearly 14 hours straight. And then today, Friday, we began to compete in the qualification matches. Now is the time our hard work meant something. I mostly helped with general fabrication, but today I temporarily became part of our drive team, being the guy setting out gears for our robotic to pick up. It was pretty fun! Much better than scouting out matches, which involved logging in every movement of every robot on the field.
Tonight, team 3184 Blaze Robotics has so far managed to get to 15th place, with the possibility of going to quarterfinals tomorrow. I am exhausted from working so much, so I apologize for not having a on topic blog post. I also apologize for the bad grammar, but it's 11:30 and I need to get this done. Next Friday though, I promise that we'll be finally on topic.
*4/21/17 fixed grammatical errors
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")
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.
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:
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:
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.
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.
Subscribe to:
Posts (Atom)


