Files
hpr-knowledge-base/hpr_transcripts/hpr0312.txt

92 lines
10 KiB
Plaintext
Raw Normal View History

Episode: 312
Title: HPR0312: Illustrious Programmer Ep02
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr0312/hpr0312.mp3
Transcribed: 2025-10-07 16:02:41
---
Broadwayelas, the
PhippetHub,
the
interpreth
Hyun
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Ha
Hello and welcome to the illustrious programmer. A learning how to program podcast brought to
you by Hacker Public Radio. This is the Alchemantist and I will be your host for the illustrious
programmer. Hello and welcome to episode two of the illustrious programmer. This is the Alchemantist. In
today's episode we're going to cover some notes. We're going to review your homework. You're going to
learn some about variables and you're going to get some new homework. So step number one, text
editors. I've learned that people who use Microsoft Windows XP are unfamiliar with the concept of a text
editor and being as illustrious programmer is to be a basic, basic programming thing. We need to
cover text editors. When you're programming you don't want any of those extra little formatting
characters that things like open office and Microsoft Word add in. They're very, very useful if
you're doing a research paper where you need to have italics and bold and underlined but they're
very, very bad when you're trying to do a computer program because you're programming translator.
See all of those extra formatting things as extra characters and gets confused. So you need a
text editor. Now there's two different kinds of text editors on XP. One is just your basic note pad
or word pad document and you can save it as a text file. Remember quote filename.py and quote to make
sure you don't save it as something else like a .txt won't work correctly. My preferred text editor and it is
available for Microsoft Windows XP is again Skype as CIT and that's freely available. Now as a note on my
plan for the illustrious programmer if there's something that is fairly obvious and also not a big deal
for computer programming I'm not going to cover it especially if it's in the book. So things like plus
minus multiplication etc. It's in the book it's very clear in the book. I'm not going to spend a lot of
time explaining it. Next note running Python in Windows you need to add the line raw underscore input at the end of your
program. Now what happens is if you're running a Python program it's going to flash on the screen and
reason it flashes is it processes it. It says I'm done processing and Windows Windows stops that
window from existing it kind of it's called killing the Windows Windows kills that window. If you add the
line raw input at the end of your program it'll wait for input and you're just going to be able to hit enter at
the end of that program and it'll close out the window so you can see the results so that the command is raw underscore input
R-A-W underscore I-N-P-U-T left parenthesis right parenthesis. Now the underscore character is that one that's on the
same key is the minus character you hit shift and then minus it'll come up with that underscore in those keyboards. Final note is that we are
following along with the Alan Downey book think Python and that can be found in HTTP colon slash slash
W-W-W dot green T press dot com slash think Python slash think Python dot HTML. Now your homework you've discovered that you've got quite a
really nifty calculator there just to kind of review 10 kilometers equals 10 divided by 1.61 and we remember from last
and that there are 1.61 kilometers in a mile so that yields the total number of miles then you would just divide your total time by your
total number of miles and you would get your average time per mile which is 7.0035 minutes or really 7 minutes when you round it up to your
points of accuracy then you need to transfer your retirement hours so you just take your total time and divide it by 60
because we don't need minutes or anything we just need your decimal and that's fine. Then miles divided by time in hours equals your miles per
hour ends up being 8.56714499893 and you can round that again to points of accuracy at 8.6 miles an hour roughly 8.5 miles an hour. There's some other
ways to do this with Python a little bit easier instead of plugging in the number every time we're going to learn about that today.
Okay, a variable is a container that represents something. Now I hesitate to use the word container because container means something else but think of it as like a bucket that you have stuff in.
Now Bob is a tomato so what you're going to do is you're going to type Bob space equals space quotation mark. I am a tomato and quote and then hit enter and you'll notice that there is no output on the
command line there it just blank output everything you've done up till now has given you an output on that line. Now type print space Bob and hit enter and you're going to see I am
tomato so it lets you know that Bob is I am a tomato pretty neat huh so we're going to break this down a little bit Bob is your variable and I am a tomato is the value of that
variable a value is the right hand side of a variable assignment so you're going to assign a value to that variable pretty neat huh. Now all values have a type. Just like you have you know
tall people short people skinny people fat people and those are the types of people and friendly people mean people so on and so forth variables all have a type that helps the computer to identify what it should be able to do with those we're going
to talk about three types right now the first type is a string and that's what you create when you said I am a tomato Bob equals I am a tomato is a string.
String stands for a string of characters so characters all strung together sentences words and that kind of thing can be considered within Python a string.
Now numbers can either be an integer or float an integer is as you're going to remember from math class a whole number one two three four I saw so forth of float is a number that can have a decimal.
So we're going to continue on we're going to work with some more variables here number space equals eighty seven again notice there's no output.
Type print number and eighty seven is going to pop up now is that an integer or float well you'll obviously know that it's an integer but how can you be positively absolutely 100% sure what you're going to use a command called the type command TYPE and it goes like this TYPE space left parentheses number right parentheses now when I say number
I'm saying to type out the word number so where we did before number equals eighty seven you're going to type in number right there the same exact variable name.
And it says it's an integer cool huh now you're going to change number you're going to say number equals eighty seven point zero.
Use the type command again exactly the same way and you're going to discover that number has become a float pretty neat huh now finally you're going to type number equals left quote eighty seven point zero right quote enter.
Now run that type command again what happened did you see that it became a string.
The reason it became a string is because of the quotation marks you have to be very very careful of this because the the program only knows what it's told when you're working with a programming language Python or see or any kind of programming language the computer only knows what you tell it so if you tell the computer that this is eighty seven it's going to Python is going to say all that's an integer you told.
me it's an integer if you say it's eighty seven point zero then it's going to say oh that's a float I know that that's a float but if you put quotation marks around it no matter if it's a float during integer it's going to say oh this is a string no matter what now you you think well that's kind of silly computers are stupid yeah computers are stupid they don't know anything more than you tell them.
Now a neat thing that is good but can cause some problems is that in Python variables are like Johnny Depp you know the actor people say that he can play any role whether that's true or not I don't know but that's what they say so you noticed before that number was an integer then it was a float and then finally it was a string and the reason is Python just tries to figure out what you're trying to do.
This is good in that you don't have to keep track of what those are but it can be bad because sometimes it'll cause little difficulties that are hard to track down.
Now finally before we before we get going on type print space one comma zero zero zero comma zero zero zero and before you hit enter you think to yourself well that's one million I know what that is that's easy but when you hit enter it becomes
one space zero space zero space and line rather and the reason is those commas.
When you put a comma in a number in Python or any programming language it treats it differently Python assumes that those are three separate numbers that you're trying to put into the computer so be very very careful format your numbers without extra things like commas or.
extraneous little punctuation if it's a decimal or you want to be a float but that decimal point in there if you want it to be an integer keep the decimal point out of it and so on and so forth so when you're typing that one million with the comma separated zeros you're telling it that you want it to print three separate things.
Now finally your homework for this this episode is to redo the assignment from the last chapter using the variables time miles and temporary so for time time's fairly easy what you can do is you can say time equals and then put in the the amount of time.
And then you can do miles equals that whole equation from before remember so miles equals 10 divided by 1.61.
Now when you do that I want you to type print miles to see what it does does it produce an integer or does it produce a float.
Experiment make sure see if you can get it to produce an integer see if you can get it to produce a float and play with that repeat that homework assignment from the previous episode make sure you get all the same results that you did last time and then make sure that you can explain why it was an integer or why it was a float.
Sometimes if you have points of accuracy that can help you to understand the whole process okay well this is the alt command to signing off have a great day.
Thank you for listening to H.P.R. sponsored by Carol dot net so head on over to C.A.R.O dot anything for all of us.
Thank you.
Thank you.