Backup of Python
Backup of Python
Chuck
0:04
Hello, my name is Charles Severance. I'm a Clinical Professor at the University of Michigan
School of Information, and I'm your instructor for this course. This course is a little different than
every programming course that I've ever taught, or I've ever taken. This course is dedicated to
the notion that every single person on the planet needs to be able to write programs and can
write programs. You do not have to have a bunch of math. I do not expect math. I do not expect
that you've taken any other programming classes. I don't expect you know anything about
computers. I think no matter what your background is, you can program. That's why it's called
Programming for Everybody. I have a couple of goals. Certainly, I want to teach you how to
program. But actually what I really want to do is teach you how to take a programming class
because it turns out that most of the other programming classes in the world are kind of difficult.
They sort of assume way too much and the teachers sort of don't even realize how much they're
expecting from students. So when you're done with this class, you can go and take another
beginning class. And that way you have this as an on-ramp to all of your programming activity.
And so I'm really excited that you're here. Another thing that I want to do is I want to teach you
how to be a mentor. I want to teach you how to be a teacher of programming. So I want you to
take all my ideas, and I want to you to help the next person. And the reason is that learning how
to program is a little sort of foggy, uncomfortable, you get stuck on things, and those things aren't
hard, I assure you. But when you're stuck on them, they feel really hard. And the best way to get
unstuck is get some help from somebody. And if they're sitting right next to you, and they can go,
"Oh look. You've just got to like add two spaces and it's fine." And you're like, "Oh, that saved me
a lot of time." So I want you to be willing to help somebody else. Another thing that's important to
me is that I want to create more teachers. Whether they're at universities, or community colleges,
or high schools, or even middle schools, or in professional situations. I have given you all of the
materials for this course at a website. They're all licensed under Creative Commons, the slides,
the autograders. I want you to in a sense adopt this textbook, and then use my teaching kit so
that you can become a teacher of this material, because I don't think that I'm naturally the only
teacher of this. And in particular, if you don't speak English as your first language, you might
want to teach this class in your native language. And so that's another reason that I give you
these materials with a free and open copyright that you can take them, you can translate them
into your language. The book has been translated into several languages. And that's really
exciting. Those books that have been translated are usually free and available. You can get print
copies that are very inexpensive and all the ecopies are free. And so this notion that I create this
kit, that you can then change the kit. You don't have to just take my class. You can change it and
you can make it work for you locally. And really, the overall goal of this is more than just like
teaching you one programming class. I think that the entire technology marketplace, and to some
degree all of business in general is becoming increasingly technical. And too many people,
young, old, regardless of education, are shut out of this sort of club where you need to know
something about technology. And so that's why we're Programming for Everybody. Regardless of
geography, regardless of ability to pay, regardless of if you have any disabilities, I want
Programming for Everybody to be everybody. I want when to just expand forever the number of
people who are capable of programming. It's an open self-sustaining ecosystem, and have you
be part of that self-sustaining ecosystem. So again, welcome to the class. I look forward to what
you do and I look forward to seeing you throughout the class.
Video: Welcome to Python - Guido van Rossum
[MUSIC] I'm Guido van Rossum. I created the Python language. I have worked on Python for 25
years and I have worked with a large group of others of course in the Python community. I'm very
excited to see you all in this class. And I'm very proud that you're using my language to learn.
Python is just the first step you're setting on the path to programming. There are many exciting
things to learn in programming. Many that you can learn using Python, many that you can learn
using other things. And you won't be alone. There will be millions of people who have gone
before you or, or who are learning Python at the same time as you. And you, you can help each
other, and you can learn together. [MUSIC]
1.2-Hardware Overview
Welcome back.
Now, we're going to talk a little bit about hardware architecture.
You might ask yourself sort of why all these terms, and words,
and central processing unit, what I want from this section is I just want to
define a few terms, so that I can use them in the rest of the course.
That's really it.
I want you to have some sense of the basic block diagram of things.
Now in the old days, I'm going to show you three generations of hardware.
I'm going to show you really old hardware from the 60s and 70s.
I'm going to show you sort of medium old hardware from the 90s and early 2000s.
And then, I'm going to show you sort of super brand new
hardware that sort of this is a Raspberry Pi and
it's the kind of highly integrated hardware that goes into things like the cellphone.
So I'll kind of be going back and
forth between three complete generations of hardware.
Play video starting at 1 minute 7 seconds and follow transcript1:07
But the picture and the concepts that I want you to understand are these terms.
Central processing unit, main memory, secondary memory unit,
and input/output devices.
So we'll start with input/output devices.
They are the way that this computer accesses the outside world.
So things like the mouse, the keyboard, right, I got a keyboard here.
Play video starting at 1 minute 31 seconds and follow transcript1:31
Keyboard.
Screen.
All these things.
I don't want to mess up the keyboard there.
And so these are the input/output devices.
There is a little, that's okay just mess up a little bit, no problem at all.
Output devices, screens, and
that's sort of how the humans in the outside world interact.
Software, the main inside the computer, we have the central processing unit, and
the main memory, and then the secondary memory.
And so it's probably easier for me to take the, neither the oldest nor
the newest, to give you a sense of what is going on here.
And so, if you had a desktop and maybe you still have one of these junky old desktops
at home, they are the ones that are big and they make noise when they start up,
they have in them a number of different parts and
the closest thing that a computer has to intelligence is this.
Central processing unit, CPU is what we call them.
And if you look at the back side of this CPU it is actually a circuit.
It's a highly sophisticated circuit with millions of transistors on it, and
you've probably heard that, millions of transistors. It runs
maybe three billion instructions per second.
What does that mean?
Well that means that an instruction is a set of electrical pulses,
maybe 32 little wires or 64 little wires.
And at three billion times a second, this is programmed to ask what's next.
And it pulls what's next in these little electric wires.
Well, where does it get the answer to what's next?
It gets the answer to what's next out of the memory. And so your program,
when you write a program, let me draw this, when you write a program,
you create a file on the secondary memory, like a Python file, and then at some point
that is loaded into the main memory, translated, and then your program is here.
And then when the CPU says what next, your program feeds its first instruction.
And then when that's done, the CPU says what's next?
It feeds the second instruction, third instruction, fourth instruction.
It's called the fetch-execute cycle.
And these two parts, the CPU and the main memory, are what participate.
And the main memory is where you kind of live.
Somewhere in there, a little tiny version of yourself is in there
answering the questions that this is asking.
Now you might say how smart is this, it's not really very smart at all. It's
a really fast hand calculator with lots of storage is the best way to think about it.
And going back to the 60s and the 70s,
this is a piece of hardware from a computer that was the size
of a room with probably 20 refrigerators, all with modules that make this up.
And in here, well you probably can't see it, you've got resistors,
transistors, and capacitors, and then wires.
The wires are all printed on this printed circuit board, otherwise known as PCB.
And so, the closest thing this has to intelligence are these transistors.
And at their simplest,
what they can do is they can sort of make really simple yes/no decisions.
And then they also can be used, if you hook them together the right way,
to store a little bit of information.
And so, when we say there are millions of transistors
packed into this little tiny square right here.
It's kind of pretty.
I mean, if you look at it, it's sort of, it looks almost like a jewel, it's so pretty.
And each one of those is a real tiny photo-imprinted transistor and
so there are millions of this.
And so the difference between 1960 and
today is this part gets smaller and smaller and smaller to the point where
literally thousands of these things are all squeezed in to that little square.
And coming back to sort of the mid-grade one, so this one here is the motherboard.
This part here is the motherboard because it's the mother of all boards and
it connects everything together.
All these components plug in and that's how they are connected together and
there's a whole bunch of wires that go back and forth on this and so
this is how your program in a sense is transported from the memory to the CPU.
And so, this motherboard connects them.
Another thing that's connected to the motherboard is secondary storage.
Now, the reason we have to have secondary memory or secondary storage
is this is designed to be really fast, the main memory is super fast.
And what happens is when the computer turns off,
your program is erased from here.
And so I originally said that you write your program, and
you put a file in here, a .py file, and
this is the same place that your Word files are, and your PowerPoints are.
And then, the .py file is kind of loaded and translated into the main memory.
And then when the computer shuts off, all this data goes away.
Secondary memory is permanent.
This does not get shut off.
And so, in the old days, this old-day stuff,
we used to store our programs and our files on our hard drive.
And you may even have a computer at home
where there's a actual physical spinning platter of magnetic media and
a little head that goes in and out to read and write the data.
And so it actually records magnetically when you put a file in,
it records it and then when the power's off the magnetic recording stays here.
And so these things, physical disk drives, are kind of going,
becoming extinct, because all the data is in little USB sticks like this, and
that's a perfectly good version of secondary memory.
But at least for us, we can look at these beautiful antique
mechanical gadgets that we used to store data magnetically when the power goes off.
Now, this one here is pretty broken.
[LAUGH] And it's pretty in bad shape, so
it's probably not really storing much of anything.
So in a summary of this picture,
the thing I really want you to get out of this picture is a series of definitions.
The Central Processing Unit is very simple,
it's the closest thing computers have to brains, but
it wants to answer the question what to do next, but we have to feed, through memory.
the answers, which is your programs. And then we have input devices,
output devices, the main memory, and
then the larger permanent storage in the secondary memory.
So, where you live inside of a computer is basically in the main memory.
When you write a program, you type it in the computer, you outside the computer
are typing on your keyboard, and you're typing Python commands into a file.
Like if x less than 3, print, right?
And then, that gets loaded into the main memory, and
so you, this is a creative version of yourself.
It's your instructions that are going to be run and
that program ends up in the main memory, and then it's run.
So, this is sort of where you live inside the computer.
Think of it that way.
You're living in main memory when your program is actually executing.
Now, it turns out that the instructions that this
central processor uses are a series of zeroes and ones.
And when I said like 32 zeroes and ones, or 64 zeroes and
ones, simultaneously are fed into this for each of the instructions.
We use a language called machine language.
And I would love some day to teach you machine language, but
we don't have time right now, and you, that is more moving towards being
a computer scientist when you start learning machine language, but
basically we don't have to worry about that too much, we write Python.
And we write in Python and
then something effectively translates it into machine language and
then machine language is the thing that runs and runs and runs and runs and so.
Someday you might take a look for that, but that's more of a computer science
thing and the software that does this translation,
which is either called a compiler or an interpreter,
we can talk more about that when you become more of a computer scientist.
But for now, we're going to worry about how to write this code and
the rest of this sort is going to fall by the wayside as we go forward.
So, I got a couple of videos here.
Play video starting at 9 minutes 36 seconds and follow transcript9:36
This one video, hopefully the YouTube URL is still good,
if not we'll try to find another way to get you linked to a good copy of it.
But it, basically, these, as I said, there are millions of transistors
in one of these things, and there's a lot of electricity going through these things.
And when your computer heats up on your lap,
it's this little part here that's working really hard.
Its doing things three billion times a second.
So someone has made a video, not a very good video, but
it's from a long time ago, where you take the cooling part off and
you watch what happens to these CPUs when they're doing all this work three billion
times a second using all this electricity and they're not properly cooled.
Another cool video that we have is a video of hard drives and
how they actually spin in reality.
This one is totally messed up because I've been beating on it for years and
playing with it, using it in all my classes for years, so it's in really bad shape.
But this video shows you how that works and how it actually spins in reality.
And you'll hear noises that if you have or had a desktop computer,
Play video starting at 10 minutes 36 seconds and follow transcript10:36
you'll kind of recognize the noise, and then you'll have an idea of what's going
on inside that computer as that secondary storage is moving around.
And like I said, secondary storage is becoming less and less relevant as we move
to solid-state storage, like the kind of storage that's in a USB stick.
Play video starting at 10 minutes 55 seconds and follow transcript10:55
So up next, we're going to talk about how we write that Python.
I talked a little about the hardware now, and
now we're going to get started writing some Python.
So welcome to this week. Last week, we talked about the theory of programming, and
computer science, and the Macarena, and all that kind of stuff, and that's cool. But now
we're going to start writing programming, writing programs using Python. And one of the
things we're trying to encourage you to do is install Python and run it, because sooner or
later you are going to have to do that, right? You're going to have to install it and run it.
We've got a bunch of videos. But in Courses One and Courses Two, you don't actually have
to do that. Now, we know that some people are using iPads, or Chromebooks, or something
else, and you can't install Python. And maybe you're at a school that can't install Python, so
it's great that you can write Python programs using software we've provided in the browser.
And we have this Python Playground, and so as you go through the course, you'll find
assignments that you'll have to do. But what this is is this is an ungraded assignment, Python
Code Playground. And so it's launched externally, using a technology called Learning Tools
Interoperability, so it's going to pop this open in a new tab. So you see that it's in a new tab,
right? And it's the Python Code Playground. Now, this is kind of like the autograder except it
has no expectations, and you can write any code that you want, okay? And so let me hit the
Reset Code button, and you can always go back to the default code, and this is the code
that's there for you. And if I want to run it, I can just say, go ahead and run this code, right?
And so the code runs, and the output's over here. So it actually ran the Python, and the
code came out over here. Now, this is a file, this is like Chapter Seven, it's even from Course
Two, so the default code here is probably not what you want to play with. You can play with
something like print('play!'), and run that. And so it runs the code, and then your output
comes here. Now, there are three files, which is later, Chapter Seven and later, that you can
use. These are the sample files that we use throughout a lot of the assignments in the book,
and away you go. And so you can do whatever you want here. It's not being graded, there's
no grade being sent back to Coursera, and so away you go. And if you're writing Python on
your laptop or your computer, you're way better to just learn how to do Python there and
then paste the code in the autograders later. But if you have no access whatsoever, that's
why we give you the Python Playground. If you want to do this in Python 2, because the
course is taught in Python 3, there's a little button down here that says switch to Python 2.
And so you can run Python 2 code in here as well if you know Python 2. In the first ten
weeks of the class, you can actually switch back and forth between submitting your
assignments in Python 3 and Python 2, but in this case. Now, the other thing that's cool
about this is that you aren't going to see this button, you're not going to see any of those
buttons. This View Student Code allows our teaching staff to take a look at your code. And
so we don't allow you to paste code into the forums, so what you can do is you can ask for
help in the forums. And the teaching staff can go in and view the student code, type in your
name or email, and then find the code that you last put in. So you can put something in here
and get some help on it. The teaching assistant can see your entire code, they can run your
code, they can do all kinds of things. And so it's a great way to communicate with the
teaching assistant. You sort of leave your code in the Playground, you ask the teaching
assistant, and then they go take a look at your code and give you some answers. When
you're all done, you simply press Done, and we're back to Week 2. But like I said, I really
would personally prefer that you build the skills on running Python on your laptop as quick
as possible. But if that's not practical for you, then that's why we have the Python
Playground here in Courses One and Two.