Learning to Program in Python

Slides:



Advertisements
Similar presentations
Python November 14, Unit 7. Python Hello world, in class.
Advertisements

Computer Science 101 Introduction to Programming.
An Introduction to Textual Programming
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
By the end of this session you should be able to...
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
The Hashemite University Computer Engineering Department
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Algorithms and Pseudocode CS Principles Lesson Developed for CS4 Alabama Project Jim Morse.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Basic Programming I Working with QBasic
Foundations of Programming: Java
Math operations 9/19/16.
Starter What does the following code do?
Topics Designing a Program Input, Processing, and Output
A Playful Introduction to Programming by Jason R. Briggs
© DMTI (2017) | Resource Materials |
Lesson 1 - Sequencing.
Simplifying Algebraic Expressions
Week of 12/12/16 Test Review.
Topic: Python’s building blocks -> Statements
Formatting Output.
Completing the Problem-Solving Process
Variables, Expressions, and IO
Unit 2 Smarter Programming.
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Introduction to Programmng in Python
Learning to Program in Python
Lesson 1 Learning Objectives
Learning to Program in Python
Learning to Program in Python
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Today’s lesson – Python next steps
Learning to Program in Python
Number and String Operations
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Programming Fundamentals (750113) Ch1. Problem Solving
An Introduction to VEX IQ Programming with Modkit
Learning to Program in Python
Learning to Program in Python
IFS410 Advanced Analysis and Design
Introduction to TouchDevelop
Introduction to Programming
Programming We have seen various examples of programming languages
Learning to Program in Python
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Unit 3: Variables in Java
Lecture 13 Teamwork Bryan Burlingame 1 May 2019.
Introduction to Programming
Working with Percentages.
Chapter 1: Creating a Program.
Introduction to Python
Python Creating a calculator.
Presentation transcript:

Learning to Program in Python Concept 1 Variables (and operators) Variables will have been used in the starter program. This is a full introduction to variables and data types, and a second lesson (this resource) introduces operators. The tasks and ideas would require several classes to ensure students have time to engage with the concept.

Learning Intentions Use the key operators in programming. From this lesson the students will be able to: Use the key operators in programming. Solve a numerical task and program their solution. This lesson is completely problem based, with students expected to discover the answers to the etasksheets themselves . The numerical task is really the first major computational thinking challenge for the students that is expected to be coded. A bigger CT challenge, presented via HTML, on the conversion of hours minutes seconds is aligned to this lesson on the website.

Fill in the Value & Data Type of the assigned variable - the assigned variable is named answer for each operation - x = 10 y = 7 Operation Code Value Data Type Operation + answer = x + y 17 INTEGER Addition - answer = x - y 3 Subtraction * answer = x * y 70 Multiplication / answer = x / y 1.42857.. FLOAT Division // answer = x // y 1 Floor % answer = x % y MODulus ** answer = x ** y 10,000,000 Exponent (power of) Encourage the students to use their IDE to figure out and understand the less familiar operations. The etasksheet above can be downloaded from the NCCA website, completed by the students and stored in their online space. Or it can be printed out for a written class task. The answers are revealed when the slide show is run. The PRIMM method will encourage engagement. (Predict Run Investigate Modify Make)

Predict the answers and the data types Data Type: Float ans_2 = 3.0 Data Type: Float ans_3 = 2 Data Type: Integer Some things to note : 9/3 gives 3.0 (float) BEMDAS applies to operators. Is x // y equivalent to int(x / y) ? This task plus the Number Buster Challenge on the next slide, form the student tasksheet 1.2. The PRIMM method will encourage engagement. (Predict Run Investigate Modify Make) ans_4 = 2.5 Data Type: Float ans_5 = 2 Data Type: Integer

Create Your Own … Number Buster Your task is to write a program that will extract each digit of a 2 digit number. The user will enter a 2 digit number such as 45 or 71. Using operators you have learned, output the first digit and the second digit of the number. User Interface Your program will prompt the user for the 2 digit number. Your program will clearly output the first digit and second digit of the number. When completed, test your program with 90, 44, 19, 91, 10. This challenge forms part of the student etasksheet 1.2. Students must write the algorithm first. The next slide shows some suggestions on how to code this problem. Encourage students, in paired programming style, to verify each other’s code and test for bugs and logical errors. Encourage students to write out their algorithms, and to use pseudo code. The Scratch symbol indicates that this task should also be done in Scratch (or similar block-based language). The html resource, containing the Scratch program and guiding the students, is part of the same folder as this Python resource. (see While loops for an extension to this challenge). Encourage the students to edit the html file to serve as part of an ePortfolio. See the file for instructions. LO 1.3 students should be able to solve problems by deconstructing them into smaller units using a systematic approach in an iterative fashion

Tips on separating digits in a number Let’s say our number is called userNumber. Let userNumber equal 73 If we MOD userNumber by 10, we get the remainder. Try 73 % 10. The reason we use 10 is because the numbers are decimal. Remind students that instead of 73 // 10 we can equally use int( 73 / 10). When students study LOOPS they will be able to offer the user unlimited amount of turns plus the option to exit the program. Also later in the course, students could test their program by programming every input from 00 to 99, again using LOOPS. If we FLOOR DIVIDE userNumber by 10, we get a whole number. Try 73 // 10. LO 1.4 students should be able to solve problems using skills of logic

Some suggestions for your program 1. Some names to consider for the variables … userNumber, firstDigit, secondDigit. 2. Remember this code from the first program? In Python, input from the user is in the form a STRING. Encourage good habits from the start, such as using variables appropriately and appropriately named. There are a multitude of style guides online such as http://www.cs.bu.edu/courses/cs108/guides/style.html. The user interface should be considered up front as part of the solution. The variable userNumber must be cast as an INTeger. 3. A suggestion for outputting the solution : print(“The first digit is : “, firstDigit)

To Recap … Number Buster Your task is to write a program that will extract each digit of a 2 digit number. The user will enter a 2 digit number such as 45 or 71. Using operators you have learned, output the first digit and the second digit of the number. User Interface Your program will prompt the user for the 2 digit number. Your program will clearly output the first digit and second digit of the number. When completed, test your program with 90, 44, 19, 91, 10. This challenge forms part of the student tasksheet 1.2. Students must write the algorithm first. The next slide shows some suggestions on how to code this problem. Encourage students, in paired programming style, to verify each other’s code and test for bugs and logical errors. Encourage students to write out their algorithms, and to use pseudo code where possible. When students study LOOPS they will be able to offer the user unlimited amount of turns plus the option to exit the program. Also later in the course, students will be asked to test their program by programming every input from 00 to 99, again using LOOPS. LO 1.7 students should be able to develop algorithms to implement chosen solutions

Generating a Random number to test your solution. In Python you can generate random numbers between any two values. The code for 2 digit numbers could be : When students study LOOPS they will be able to offer the user unlimited amount of turns plus the option to exit the program. Also later in the course, students will be asked to test their program by programming every input from 00 to 99, again using LOOPS. random is the module which contains the commands. randint stands for random integer. (It is inside the random module)

Generating a Random number to test your solution However, Python does not have the random command in the standard library you have been using up to this point. So you must import the module. It could look like this : Encourage the students to incorporate this test using random numbers. It will be needed in the CT challenge on rolling a dice in the Input Output lesson. When students study LOOPS they will be able to offer the user unlimited amount of turns plus the option to exit the program. Also later in the course, students may be asked to test their program by programming every input from 10 to 99, again using LOOPS.

Create Your Own … 3 digit Number Buster Can you enhance your program to extract each digit from a 3 digit number? The user will enter a 3 digit number such as 545 or 708. Using operators you have learned, output the first digit, the second digit and third digit of the number. Generate a random 3 digit number to test your code. Some students may progress to this slightly more difficult challenge. Or it could be set as a class task or home challenge. Preferably, a task of this nature is the ideal opportunity for a collaborative and shared task approach between small groups of students. The fist major Computational Thinking challenge, presented via HTML, on the conversion of seconds to hours minutes seconds is aligned to this lesson on the website. LO 1.20 students should be able to collaborate and assign roles and responsibilities within a team to tackle a computing task

CT CHALLENGE A friend of yours needs a program that can convert seconds into hours, minutes and seconds. In pairs develop an algorithm to solve this problem, write a program to carry out the conversion and reflect on the design process. The full CT challenge, with some guidance, is on the ncca website in the variables section. Ask the students to perform this Computational Thinking challenge …. The assumption at this point is they have studied variables, operators and basic input and output. All CT challenges are developed on a html platform, aligned to the lesson, and with guidelines on solutions, writing the pseudocode and a fully worked solution in Python. LO 1.23 students should be able reflect and communicate on the design and development process

How do you know how to write correct PYTHON or find out how to do stuff? Some good sites for help with Python … 1. docs.python.org … tutorial 2. Runestone Academy - How to Think Like a Computer Scientist 3. Stack Overflow A resourceful student is an extra teacher and one less student. There are also a multitude of online style guidelines, such as : http://www.cs.bu.edu/courses/cs108/guides/style.html

Learning Review Solve a numerical task and program my solution. From this lesson I am able to: Use the key operators in programming. Solve a numerical task and program my solution. Students should now be able to solve a problem and begin to think (algorithmically) in terms of automating the solution.