Cs2 Ch1

12
COMPUTER SCIENCE 2: INTRODUCTION TO PROGRAMMING CONCEPTS CHAPTER 1

Transcript of Cs2 Ch1

Page 1: Cs2 Ch1

COMPUTER SCIENCE 2:INTRODUCTION TO

PROGRAMMING CONCEPTS

CHAPTER 1

Page 2: Cs2 Ch1

CHAPTER 1

We are going to learn about programming in general…How to think logically and problem solve. The programming language we will use is Python. This is not meant to be a class in Python, but that is the language we use here…It is free after all.

No…Not this kind of python!

Page 3: Cs2 Ch1

CHAPTER 1 Computers needs 2 things

to run your code – an editor and an interpreter. The editor is what you use to write the code. The interpreter makes the text into binary code that the machine can understand. Our interpreter is Python. Python comes with an application called IDLE which does both functions. Such a program is known as an IDE – Integrated Development Environment.

Page 4: Cs2 Ch1

CHAPTER 1

Complete the following exercise. We will go over your answers when everyone is finished.

Page 5: Cs2 Ch1

CHAPTER 1 Here’s what the

finished code should look like -

Now let’s take a closer look at some of the elements of this code…

Page 6: Cs2 Ch1

CHAPTER 1

First, we need to realize that there are variables being used. What’s a variable? Basically, a variable is a label for data.

So what are the variables in this code?

Page 7: Cs2 Ch1

CHAPTER 1

Start by going to the Start button, choosing All Programs, scroll down and click on the Python 3.0 folder, and finally, click on the IDLE(Python GUI).

The Python shell should open up just like this…

Page 8: Cs2 Ch1

CHAPTER 1

Once the code is entered correctly, the next thing you should do is save your work. Go to the ‘File’ menu and choose ‘Save As’. Name your file game.py.

Next, go to the ‘Run’ menu and choose ‘Run Module’.

Page 9: Cs2 Ch1

CHAPTER 1

It would be useful to know more than whether your guess is right or wrong. Like maybe if your guess should be higher or lower.

Page 10: Cs2 Ch1

CHAPTER 1

Complete the “Program Modification” exercise on the handout.

Page 11: Cs2 Ch1

CHAPTER 1

Guess == 5

True

False

Print(“You Win!”)

Too High!

Too Low!

True

False

Game Over!

Guess > 5

Page 12: Cs2 Ch1

CHAPTER 1

Now we need to look at how to write the additional code for the new branch that we have added to the false path…

Guess == 5

Print(“You Win!”)

Guess > 5 Too

High!

Too Low!

Game Over!