An Introduction to Textual Programming

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Advertisements

Microsoft® Small Basic
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
A revision guide for programming with python. 1.A program is a set of instructions that tells a computer what to do. 2.The role of a programmer is to.
Introduction to Python
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
Python Lesson Week 01. What we will accomplish today Install Python on your computer Using IDLE interactively to explore String Variables if/else while.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Decision Structures, String Comparison, Nested Structures
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
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.
Introduction to Programming
GCSE Computing: Programming GCSE Programming Remembering Python.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
Getting Started With Python Brendan Routledge
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Introduction to Programming
GCSE COMPUTER SCIENCE Practical Programming using Python
Whatcha doin'? Aims: To start using Python. To understand loops.
Week of 12/12/16 Test Review.
Introduction to Python
IF statements.
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Introduction to Programming
Variables, Expressions, and IO
Introduction to Programmng in Python
Python I/O.
Introduction to Programming
Loops CIS 40 – Introduction to Programming in Python
Introduction to TouchDevelop
Introduction to Programming
Introduction to Programming
A look at Python Programming Language 2018.
Python programming exercise
Introduction to Programming
Introduction to Programming
Python SAT 1 Feedback.
Presentation transcript:

An Introduction to Textual Programming KS3 Python An Introduction to Textual Programming

Python 1 Todays objectives: Use the Print function Store Variables Create a conversation Carry out calculations

Getting Started Open your Unit 2 Programming folder Create another folder called “Python Practice” This is where you are going to save all your Python practice work!

The Basics Open IDLE (Python GUI) Click File  New Window This allows you to write code, which is checked line by line as you write it. Click File  New Window This allows you to write full programs and then run them. If you make a mistake you will not know until you run it.

Before we start Spelling and Capital letters are essential in Python!!!! 1 missed capital letter and your program may not work. Make notes in your exercise books, this will help you later!

Text

Open Python Now open Python. Type print (“Hello World”) Press enter Welcome to Programming! FYI: In programming text is knows as a string. Strings include all letters, numbers and characters.

User Input Now lets get the user to input some text: Type: input (“What is your name”) What happens? What would make it neater? Code What is does \n Goes to a new line \t Creates a tab indent

Useful Code What is does \n Goes to a new line \t Creates a tab indent

Manipulating Strings Method Description Example capitalize() Changes the strings first letter to upercase string.capitalize() upper() changes the string to all uppercase letters string.upper() lower() changes the string to all lowercase letters string.lower() replace(old, new) replaces a letter with another letter string.replace (‘o’, ‘*’) count(x) returns the number of occurrences of x string.count(‘o’) find(x) finds the index of the first occurrence of x or -1 if its not found. string.find (‘o’) isalpha() Returns true ii string is all letters string.isalpha() isnumeric() Returns true ii string is all numbers string.isnumeric()

Variables You learned about variables in Scratch. You can assign variables in a similar way in Python. Try: name = input (“Please enter your name: \n”) print (“Hello”, name) Try asking more questions and setting variables. Can you create a conversation? What do you notice about using text? Do you have to put “ “ around variables?

MAths

Try These 8*7 10253/565 568+452 45855-65 “Hello ” * 3

Lesson 2

Variables Remember you can think of a variable as being a container where you can store data or a value for use later. You can choose virtually any name for a variable, except for protected words. Ways of storing a variable: A = 8 Try : A*A a,b,c = 1,2,3 Try: a+b+c

Good To Know If you set a variable you can change the variable like this: a = 9 a = 9 + 1 (So now a = 10) a = a + 1 (Again a = 10)

NEED TO KNOW There are different types of numbers that you can use in python. We are going to look at integers. Integer: A whole number, not a fraction To convert something x to an integer, type the following: int(x) If you ask the user for input it will automatically be a string so you will need to convert it to an integer. Best way: no = int (input (“Please enter a number: \t”)) no will be an integer!

Logic: Think How could you write the code to ask the user for a number and then multiply the number by 10? Write a program to ask the user for a number and multiply it by 10. DON’T USE THE SHELL  Press File, New

Try converting Ask the user for a number: Set the number as a variable Then multiply their number by 5.

Now you have the basics lets start programming

First Program Now lets write our first proper program. Click File  New This will open up a new window This is where you will write your code. Press F5 to run your code. You must save the work in your H Drive  Python Practice Folder

Don’t forget to convert the input to an integer. Task Write a program to ask a user for a number of hours and then convert it to minutes. How can you convert from hours to minutes? Save it as “Hour to Minute Convertor” Extension: Create other conversion programs: Miles to Kilometres Feet to Meters Years to days Years to minutes Or anything else you think might be useful. Don’t forget to convert the input to an integer.

Lesson 3

Reminder print (“Hello World”) input (“What is your name”) name = input (“Please enter your name: \n) print (“Hello”, name) A = 8 no = int (input (“Please enter a number: \t”)) int(x)

IF Statements What can you remember from IF statements from Scratch? Its very similar in Python.

If Else if expression: statement(s) else:

Try it. Write a program which asks the user for a number between 1 and 10 and then tells them if it is over 5 or under 5. Save your program

Lesson 4

IF ELIF ELSE What happens if you want to check more than one situation. E.G: If you wanted to calculate if someone was a child, teenager, or Adult. IF ELIF and ELSE can be used for this.

IF, ELIF, ElSE if expression1: statement(s) elif expression2: elif expression3: else:

Try it Write a program to say whether a person is a child, teenager, or adult. If they are over 18 they are an adult If they are under 13 they are a child Otherwise they are a teenager

The Code

While

While Loop

Try it From 10 count to 50 using a while loop. Advanced: Ask the user for the start number Ask the user for the last number Print the list of numbers You could ask the what jumps they want to go up to. E.G: Count in 10s up to 100.

Assessment

Assessment Level 3: Make something happen by writing your own set of instructions Level 4: Create a set of instructions for a programme, and improve your instructions to make the programme more efficient Level 5: Create precise and accurate sequences of instructions

Assessment You must create an original game. The game will be in the format of a quiz. The way the game looks and works will be completely up to you. Your game will have the following; Ask the users name and use this in the quiz At least 3 questions A scoring system At the end of the game it will say the users score Your game might include: An introduction to the quiz Anything else you think would improve the game!

Can you put together what you learned to create a game. Last Python Lesson

Random Function Create a game where the computer will generate a random number and the user will try and guess the number. The game will feedback if the guess is too high or too low. You will need to use the while or for loop to get the game to keep running.

Random

Random Function Create a game where the computer will generate a random number and the user will try and guess the number. The game will feedback if the guess is too high or too low. You will need to use the while or for loop to get the game to keep running.

Guessing Game Set a variable as a random number Ask the user to enter a number and save as a variable. If the user number is smaller than the computer number then say its to small. If its too big say its too big. If they are the same say the got it.