SlideShare a Scribd company logo
1 of 12
Computer Science 2:Introduction to Programming Concepts Chapter 1
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!
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.
Chapter 1 Complete the following exercise.  We will go over your answers when everyone is finished.
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…
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?
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…
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’.
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.
Chapter 1 Complete the “Program Modification” exercise on the handout.
Chapter 1 Print(“You Win!”) Game Over! Guess == 5 Too High! True Guess > 5 True False  False Too Low!
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… Print(“You Win!”) Game Over! Guess == 5 Guess > 5 Too High! Too Low!

More Related Content

What's hot (9)

Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
 
Python programming
Python programmingPython programming
Python programming
 
What is code - Part 1
What is code - Part 1What is code - Part 1
What is code - Part 1
 
Machine Learning as a MicroService
Machine Learning as a MicroServiceMachine Learning as a MicroService
Machine Learning as a MicroService
 
Ios machine learning
Ios machine learningIos machine learning
Ios machine learning
 
Lesson 8 Encryption
Lesson 8 EncryptionLesson 8 Encryption
Lesson 8 Encryption
 
Small basic
Small basicSmall basic
Small basic
 
Lesson1: Introduction to Programming
Lesson1: Introduction to ProgrammingLesson1: Introduction to Programming
Lesson1: Introduction to Programming
 
Java
JavaJava
Java
 

Viewers also liked

Outcomes & ICT KVA Nov 2012
Outcomes & ICT KVA Nov 2012Outcomes & ICT KVA Nov 2012
Outcomes & ICT KVA Nov 2012Superhighways
 
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"Miguel Monteiro
 
Social media-crisis-comms-decision-tree
Social media-crisis-comms-decision-treeSocial media-crisis-comms-decision-tree
Social media-crisis-comms-decision-treeAdam Lewis
 
зайны сургалт
зайны сургалтзайны сургалт
зайны сургалтZaya80
 
Nueva personalidad de Homero
Nueva personalidad de HomeroNueva personalidad de Homero
Nueva personalidad de HomeroFernando Matta
 
Kva ict tools for collaboration
Kva ict tools for collaborationKva ict tools for collaboration
Kva ict tools for collaborationSuperhighways
 
Turning acquisition on its head
Turning acquisition on its headTurning acquisition on its head
Turning acquisition on its headNTCities
 
Menoresyusodetecnologa
Menoresyusodetecnologa Menoresyusodetecnologa
Menoresyusodetecnologa XaviOrantes
 
Residential Real Estate
Residential Real EstateResidential Real Estate
Residential Real EstateCurt Cloyd
 
олон нийтийн санал бодлын нийгмийн мөн чанар
олон нийтийн санал бодлын нийгмийн мөн чанаролон нийтийн санал бодлын нийгмийн мөн чанар
олон нийтийн санал бодлын нийгмийн мөн чанарBayarmaa Anu
 
цахим хэрэглэгдэхүүн
цахим хэрэглэгдэхүүнцахим хэрэглэгдэхүүн
цахим хэрэглэгдэхүүнZaya80
 
Reseña prsentaciones orales
Reseña prsentaciones oralesReseña prsentaciones orales
Reseña prsentaciones oralesadry160810
 
Undarmaa 110404213616-phpapp02
Undarmaa 110404213616-phpapp02Undarmaa 110404213616-phpapp02
Undarmaa 110404213616-phpapp02Bayarmaa Anu
 

Viewers also liked (20)

Outcomes & ICT KVA Nov 2012
Outcomes & ICT KVA Nov 2012Outcomes & ICT KVA Nov 2012
Outcomes & ICT KVA Nov 2012
 
Raul Redes Sociales
Raul     Redes SocialesRaul     Redes Sociales
Raul Redes Sociales
 
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"
Trabalho de oc - " de que forma e que o mar pode ajudar a ultrapassar a crise"
 
Social media-crisis-comms-decision-tree
Social media-crisis-comms-decision-treeSocial media-crisis-comms-decision-tree
Social media-crisis-comms-decision-tree
 
зайны сургалт
зайны сургалтзайны сургалт
зайны сургалт
 
10а нуур
10а нуур10а нуур
10а нуур
 
Nueva personalidad de Homero
Nueva personalidad de HomeroNueva personalidad de Homero
Nueva personalidad de Homero
 
Osteoporsis secundaria
Osteoporsis secundariaOsteoporsis secundaria
Osteoporsis secundaria
 
Kva ict tools for collaboration
Kva ict tools for collaborationKva ict tools for collaboration
Kva ict tools for collaboration
 
Turning acquisition on its head
Turning acquisition on its headTurning acquisition on its head
Turning acquisition on its head
 
Menoresyusodetecnologa
Menoresyusodetecnologa Menoresyusodetecnologa
Menoresyusodetecnologa
 
Residential Real Estate
Residential Real EstateResidential Real Estate
Residential Real Estate
 
олон нийтийн санал бодлын нийгмийн мөн чанар
олон нийтийн санал бодлын нийгмийн мөн чанаролон нийтийн санал бодлын нийгмийн мөн чанар
олон нийтийн санал бодлын нийгмийн мөн чанар
 
2013.03.18新聞剪報
2013.03.18新聞剪報2013.03.18新聞剪報
2013.03.18新聞剪報
 
цахим хэрэглэгдэхүүн
цахим хэрэглэгдэхүүнцахим хэрэглэгдэхүүн
цахим хэрэглэгдэхүүн
 
Reseña prsentaciones orales
Reseña prsentaciones oralesReseña prsentaciones orales
Reseña prsentaciones orales
 
Bolola
BololaBolola
Bolola
 
Undarmaa 110404213616-phpapp02
Undarmaa 110404213616-phpapp02Undarmaa 110404213616-phpapp02
Undarmaa 110404213616-phpapp02
 
Caja de herramientas
Caja de herramientasCaja de herramientas
Caja de herramientas
 
Tic´s en educación especial
Tic´s en educación especialTic´s en educación especial
Tic´s en educación especial
 

Similar to CS2 Intro to Programming Concepts Chapter 1

Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptxHaythamBarakeh1
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
Getting started with python
Getting started with pythonGetting started with python
Getting started with pythonTechieHours
 
Computer Science 111 Computer Science I with Java and Pyth.docx
Computer Science 111 Computer Science I with Java and Pyth.docxComputer Science 111 Computer Science I with Java and Pyth.docx
Computer Science 111 Computer Science I with Java and Pyth.docxmccormicknadine86
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxMohammad300758
 
Year 7 lesson 1 introduction to programming
Year 7 lesson 1   introduction to programmingYear 7 lesson 1   introduction to programming
Year 7 lesson 1 introduction to programmingtmoncrieff
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonmckennadglyn
 
Python games
Python gamesPython games
Python gamesdxbeeh
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicSara Samol
 
Application development with Python - Desktop application
Application development with Python - Desktop applicationApplication development with Python - Desktop application
Application development with Python - Desktop applicationBao Long Nguyen Dang
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicAn I
 
Tips for Happier Python Debugging
Tips for Happier Python DebuggingTips for Happier Python Debugging
Tips for Happier Python DebuggingChun-Hao Chang
 

Similar to CS2 Intro to Programming Concepts Chapter 1 (20)

Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptx
 
Python programming
Python programmingPython programming
Python programming
 
1.Basic_Syntax
1.Basic_Syntax1.Basic_Syntax
1.Basic_Syntax
 
Python basic syntax
Python basic syntaxPython basic syntax
Python basic syntax
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
Getting started with python
Getting started with pythonGetting started with python
Getting started with python
 
Computer Science 111 Computer Science I with Java and Pyth.docx
Computer Science 111 Computer Science I with Java and Pyth.docxComputer Science 111 Computer Science I with Java and Pyth.docx
Computer Science 111 Computer Science I with Java and Pyth.docx
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptx
 
Year 7 lesson 1 introduction to programming
Year 7 lesson 1   introduction to programmingYear 7 lesson 1   introduction to programming
Year 7 lesson 1 introduction to programming
 
python-handbook.pdf
python-handbook.pdfpython-handbook.pdf
python-handbook.pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introducing Small Basic.pdf
Introducing Small Basic.pdfIntroducing Small Basic.pdf
Introducing Small Basic.pdf
 
Python games
Python gamesPython games
Python games
 
Core python programming tutorial
Core python programming tutorialCore python programming tutorial
Core python programming tutorial
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
Application development with Python - Desktop application
Application development with Python - Desktop applicationApplication development with Python - Desktop application
Application development with Python - Desktop application
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
Moreno Xec
Moreno XecMoreno Xec
Moreno Xec
 
kecs105.pdf
kecs105.pdfkecs105.pdf
kecs105.pdf
 
Tips for Happier Python Debugging
Tips for Happier Python DebuggingTips for Happier Python Debugging
Tips for Happier Python Debugging
 

Recently uploaded

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 

Recently uploaded (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 

CS2 Intro to Programming Concepts Chapter 1

  • 1. Computer Science 2:Introduction to Programming Concepts Chapter 1
  • 2. 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!
  • 3. 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.
  • 4. Chapter 1 Complete the following exercise. We will go over your answers when everyone is finished.
  • 5. 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…
  • 6. 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?
  • 7. 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…
  • 8. 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’.
  • 9. 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.
  • 10. Chapter 1 Complete the “Program Modification” exercise on the handout.
  • 11. Chapter 1 Print(“You Win!”) Game Over! Guess == 5 Too High! True Guess > 5 True False False Too Low!
  • 12. 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… Print(“You Win!”) Game Over! Guess == 5 Guess > 5 Too High! Too Low!

Editor's Notes

  1. The variables are g and guess. The first g assigns the value entered the name g. The int(g) creates a number version of g called guess.We also want to talk about the difference between = and ==. = means ‘set the value to’ and ==means ’are these two things equal?’ This will most always be paired with an ‘If’ statement, which we will discuss more coming up.
  2. Once you have the Python shell open, type in the code just as it appears in the activity we completed earlier. Yes, that includes the indents.
  3. See what happens if you guess low. Once you do this, to take another guess you must run the module again.
  4. What sort of answers did you come up with? The answer for 5 we should already know. Otherwise, we only need to indicate if the guesses are too high or too low.
  5. Let’s think about the code as a roadway. Let’s see how we can add in the directions “Too high” and “Too low”.Look at the first piece…At the intersection you must make a decision…Does your guess = 5? What then would the 2 branches be – One would be true if the answer does equal 5, the other would be false if the answer is not 5.T he answer being 5 or not is the branch condition – or the condition that must be met to choose one of 2 paths in the program – the paths or the true or the false branches. To run the true branch condition the guess must = 5. To run the false branch, the guess must be anything other than 5.So, if you run the true branch what should the result be? Print(“You Win!”)If you run the false branch though, we want to give the user more information to allow them to make a better guess the next time they play the game. How can we do this? Let’s tell the user if their guess is too high or too low so that the next time the program is run they can make a more educated guess. And like with our first branch , we will need a branch condition. What could that be? Guess > 5Once we check our branch condition, we need to set a value for the true or false branch – let’s use ‘Too High’ or ‘Too Low’. With either choice, we get back to the finish, just as we would with the original true branch – ‘Game Over!’
  6. Pg 21