print( Hello, World! ) NCSS Challenge - Beginners Week 3 Part 1

Similar documents
Python Loops and String Manipulation

Python Lists and Loops

Introduction to Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Exercise 1: Python Language Basics

5544 = = = Now we have to find a divisor of 693. We can try 3, and 693 = 3 231,and we keep dividing by 3 to get: 1

The 5 P s in Problem Solving *prob lem: a source of perplexity, distress, or vexation. *solve: to find a solution, explanation, or answer for

Introduction to Data Structures

Ukulele Music Theory Part 2 Keys & Chord Families By Pete Farrugia BA (Hons), Dip Mus, Dip LCM

Philosophical argument

Session 7 Fractions and Decimals

Calculate Highest Common Factors(HCFs) & Least Common Multiples(LCMs) NA1

Python Programming: An Introduction to Computer Science

Objective. Materials. TI-73 Calculator

Excel: Introduction to Formulas

YOUTH SOCCER COACHES GUIDE TO SUCCESS Norbert Altenstad

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Chapter 2. Making Shapes

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

Money and shopping 8.1 Online banking. Beginner s guide to. Wider interests

1.6 The Order of Operations

Base Conversion written by Cathy Saxton

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Dr. Candace Walkington, Assistant Professor of Mathematics Education Southern Methodist University

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Getting Started with WebSite Tonight

Vieta s Formulas and the Identity Theorem

Ask your teacher about any which you aren t sure of, especially any differences.

Lowercase Letters Capital Letters Picture Cards

VLOOKUP Functions How do I?

Pigeonhole Principle Solutions

0.8 Rational Expressions and Equations

An Introduction to Number Theory Prime Numbers and Their Applications.

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Solution to Homework 2

How To Print To Scale With Easy Blue Print

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

MOST FREQUENTLY ASKED INTERVIEW QUESTIONS. 1. Why don t you tell me about yourself? 2. Why should I hire you?

6.170 Tutorial 3 - Ruby Basics

Turtle Power. Introduction: Python. In this project, you ll learn how to use a turtle to draw awesome shapes and patterns. Activity Checklist

Regions in a circle. 7 points 57 regions

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?

Section V.3: Dot Product

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Prime Time: Homework Examples from ACE

Writing Thesis Defense Papers

Chapter 11 Number Theory

some ideas on essays and essay writing

Linear functions Increasing Linear Functions. Decreasing Linear Functions

COMP6053 lecture: Relationship between two variables: correlation, covariance and r-squared.

Social Return on Investment

OA4-13 Rounding on a Number Line Pages 80 81

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

HOST TEAM with Church Online

THE WISDOM OF 14 ACCOUNTING TEXTBOOKS.

Assertive Communication

CHAPTER 18 Programming Your App to Make Decisions: Conditional Blocks

Not agree with bug 3, precision actually was. 8,5 not set in the code. Not agree with bug 3, precision actually was

Using Regular Expressions in Oracle

Python Programming: An Introduction to Computer Science

C H A P T E R Regular Expressions regular expression

Writing Simple Programs

(Refer Slide Time: 2:03)

HOW TO PREPARE FOR YOUR PARENT INTERVIEW By The Testing Mom

Grade 2 Lesson 3: Refusing Bullying. Getting Started

Chapter 4: Computer Codes

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Aim To help students prepare for the Academic Reading component of the IELTS exam.

TEACHER S GUIDE TO RUSH HOUR

arrays C Programming Language - Arrays

Section 4.1 Rules of Exponents

STEAM STUDENT SET: INVENTION LOG

CS106A, Stanford Handout #38. Strings and Chars

The Fruit of the Spirit is Love

GUESSING BY LOOKING AT CLUES >> see it

My Favorite Futures Setups. By John F. Carter

Working with whole numbers

Python Programming: An Introduction To Computer Science

Top Ten Mistakes in the FCE Writing Paper (And How to Avoid Them) By Neil Harris

Internet basics 2.2 Staying safe online. Beginner s guide to. Basics

The Force Table Vector Addition and Resolution

8 Strategies for Designing Lesson Plans to Meet the CCSS Opinion and Argument Writing Requirements

Udacity cs101: Building a Search Engine. Extracting a Link

Sources: On the Web: Slides will be available on:

Astrid Roe. What has Norway done to improve students reading skills and reading engagement?

Best Practice Guidelines for Internet and Telephone Banking Providers. For services to personal customers

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

chapter >> Consumer and Producer Surplus Section 3: Consumer Surplus, Producer Surplus, and the Gains from Trade

Anger Management Course Workbook. 5. Challenging Angry Thoughts and Beliefs

Marginal and absorption costing

Name: Section Registered In:

Day One: Least Common Multiple

CAs and Turing Machines. The Basis for Universal Computation

Components of a Reading Workshop Mini-Lesson

SP500 September 2011 Outlook

TeachingEnglish Lesson plans. Conversation Lesson News. Topic: News

WRITING EFFECTIVE REPORTS AND ESSAYS

Code Kingdoms Learning a Language

Transcription:

print( Hello, World! ) NCSS Challenge - Beginners Week 3 Part 1

What will we cover? Manipulating strings; Uppercase and lowercase; Parts of strings; Characters in a string.

What does this cover? Implement simple digital solutions as visual programs with algorithms involving branching (decisions) and user input (ACTDIP011) Recognise different types of data and explore how the same data can be represented in different ways (ACTDIK008) Define problems in terms of data and functional requirements drawing on previously solved problems (ACTDIP017)

1 Manipulating strings

Making decisions with strings We ve seen how to make decisions with strings: name = input('what is your name? ') if name == 'Andrew': print("that's my brother's name!" But what about what we want to check isn t exactly equal?

Substrings within a string We can check if a smaller string is in a bigger string: msg = 'concatenation is fun' print('cat' in msg) True print('dog' in msg) False we can also check print('cat' not in msg) False

Substrings as conditions of if statements We can use these checks as the condition in if statements! name = input('enter your name? ') if 'x' in name: print('your name contains an x!') else: print('no "x" in your name.')

Pedagogical Philosophy - Think ahead! Now is a great time to ask students to consider any limitations of the previous code snippet. Recall that computers are very precise and exact. Will that code really test if any x is in their name? Perhaps get students to shout out names. (Xavier is a good one!) This leads on nicely to modify case, which we will look at next.

Test it out! Try the first question now!

2 UPPERCASE and lowercase

Using string methods to change the case of strings We can use string methods to modify a string: msg = 'I know my ABC' print(msg.lower()) i know my abc The msg string contains a message in mixed case, and when you call the lower method it gives back a new message in lowercase only.

String methods don t change what s in the variable! However, the contents of the variable don t change! msg = 'I know my ABC' print(msg.lower()) i know my abc print(msg) I know my ABC We need to save it in a new variable to keep it! new_msg = msg.lower()

Changing text to uppercase Just as lower changes text to lowercase, upper changes it to uppercase! msg = 'I know my ABC' new_msg = msg.upper() print(new_msg) I KNOW MY ABC Note that the original contents of msg haven t changed! print(msg) I know my ABC

Teacher Aside! Frequent hiccup concept! Students are often confused about what makes a change to the variable, and what they need to save in a new variable! You can save a changed version in the same variable! msg = 'I know my ABC' msg = msg.upper() print(msg) I KNOW MY ABC

Testing the case of a string Instead of changing the case of a string, we might just want to test it! msg = 'a lowercase string!' print(msg.islower()) True print(msg.isupper()) False We can also use this as the condition in if statements!

Test it out! Try the second question now!

3 Parts of a string

How long is a (piece of) string? We can find out how long a string is using the len function: print(len('hello World!')) 12 This counts all the characters, including the 5 letters in "Hello", the space, the 5 letters in "World", and the exclamation mark.

Counting specific characters in a string We can find out how long a string is using the len function: msg = 'Hello World!' print(msg.count('l')) 3 You can also count multi-character strings: msg = 'Hello World!' print(msg.count('ll')) 1

Teacher Aside! Method review The convention for calling string methods is that the string we are manipulating comes first, and then the method name, with any other information that is required passed in as arguments. msg = 'I know my ABC' msg.upper()

Replacing parts of a string (a substring) The replace method replace a substring: msg = 'Hello World!' print(msg.replace('l','x')) HeXXo WorXd! Similarly, can also replace multi-character strings: msg = 'Hello World!' print(msg.count('hello','goodbye')) Goodbye World!

Test it out! Try the third question now!

4 Characters in a string

Accessing parts of a string (a substring) We can access a single character using the square bracket subscripting or indexing operation: msg = 'hello world' print(msg[0]) h print(msg[1]) e Careful! In computer science, we start counting from 0 rather than from 1!

Accessing parts of a string (from the end!) We can also access a single character indexing from the end of the string, using negative numbers: msg = 'hello world' print(msg[-1]) d print(msg[-5]) w

Teacher Aside! Ask the class! This is a great opportunity to ask the class to guess at which letter they think would be referenced by a specific index. It s also a good chance, before the next slide, to ask them what they think might happen if you entered an index that doesn t exist - e.g. character 15 in a 12 character string.

Teacher Aside! A common question is why, if we count from 0 for the beginning of a string, don t we count from -0 at the end of a string. Python works by evaluating things from the inside, out. So Python would evaluate -0, which is the same as 0, and then look up the string index 0! So, name[0] is the same as name[-0]

Accessing parts of a string that don t exist What happens if we index beyond a string s length? msg = 'hello world' print(msg[10]) d print(msg[11]) Traceback (most recent call last)... IndexError: string index out of range The string has 11 characters, but we are trying to access character 12. (Remember we count up from 0!)

Test it out! Try the fourth question now!

Any Questions? Find me at: @groklearning nicky@groklearning.com