Can You Compute?
  • HOME
    • Yr 6
    • Revision
    • Class of 2017
    • COVER LESSON FB
    • Yr 10: Program of Study 2016
    • Yr 11:Coming soon
    • Student Showcase
  • KS3
    • Term 6: Databases
    • Term 5 Scratch
    • Term 4 Websites
    • Term 3 Spreadsheets
    • Term 2: Binary & Algorithms
    • Term 1: Basics and Hardware
  • J277/01 NEW
    • EPIC FAILS
    • Intro Lessons
    • 1.1 System Architecture >
      • 1.1.1: The CPU
      • 1.1.1: Parts of the CPU
      • 1.1.2: The CPU in action
      • CPU Recap Lesson
      • Little Man Computer
      • 1.1.3: Embedded Systems
      • RISC & CISC
      • End of Unit Exam
    • 1.2 Memory and Storage >
      • 1.2.1: Primary Storage (Memory)
      • Intro to Units of Memory
      • 1.2.2 Secondary Storage
      • How stuff works
    • 1.2.3 Units & Data Capacity
    • 1.2.4 Data Storage >
      • 1.2.4 Binary Conversion
      • 1.2.4 Binary Addition
      • L4: Hexadecimal
      • L5: Recap
      • L6: Characters
      • L7: Images
      • L8: SenseHAT images
      • L9: Sound & Sampling
      • L10: Code Sound
      • L11: Compression Part 1
      • L12: Compression Part 2 >
        • Compression
      • What do you know?
  • J276/02 old
    • Unit 2 Overview
    • 2.1 Algorithms >
      • L1: Intro to Algorithms
      • L2: The Knight's Tour
      • L3: Bresenham
      • L4: Searching Algorithms
      • L5: Bubble Sort
      • L6: Insertion Sort
      • L7: Merge
      • L8: Sorting Recap
      • L9: Creating Algorithms
      • L10: Pseudocode
      • L11: Interpreting Algorithms
      • L12: End of Unit Test
    • 2.2 Programming Techniques >
      • Coding Intro
      • L1: Programming Concepts
      • L2: Sequence, Selection & Iteration
      • L3: SSI Practice
      • L4: String Manipulation
      • L5: Secret Codes
      • L6: File Handling
      • L7: Use of records to store data
      • L8: SQL
      • L9: SQL Python
      • L10 ,11, 12: Arrays
      • L13: Functions
      • L14: Data Types
      • L15: Casting
      • L16 -17: Test and Code
    • 2.3 Robust Programs >
      • L1 : Defensive Design
      • L2 : Testing Programs
    • 2.4 Computational Logic >
      • L1: Comp. Logic 1
      • L2: Comp. Logic 2
      • L3: Operators (Python)
    • 2.5 Translators & Language >
      • L1: Types of Languages
      • L2: Translators
  • Yr 9
    • Year End Examination
    • iMedia 5: Comics
    • iMedia 4: School Brochure
    • iMedia 3: Presentations
    • iMedia 2: Review and Mail Merge
    • iMedia 1: IT Letter Writing
    • L10: Intro to iMedia
    • L9 Building a Computer
    • L8: Buying a House
    • L7: Logic Gates
    • L6: Binary
    • L5: CS Alan Turing
    • L4: Spreadsheets
    • L3: JS in an Hour!
    • L2: Intro to Coding
    • L1: CS Compression
  • Py
    • Coding Concepts
    • Writing your first Program
    • Python Pages
    • Python Playground
    • Strings
    • Python Operators
    • Functions
    • Conditions
    • Try and Except
    • Break and Continue
    • Odd codes
  • Py +
    • Looping
    • Why does my code not work?
    • Errors
    • Validation
    • Lists
    • Lists again
    • Looking for data in String
    • Writing to Files
    • Read, Write & Sorting Data
  • CODING
    • Magic Python
    • Alan Turing
    • Brian the Turtle
    • Grade Calculator
    • Nested IF Hotels
    • Vending Machine
    • A Looping Menu
    • For
    • Christmas Coding
    • JS in an Hour!
    • CSS + HTML
    • Medical Claims
    • Hour of Code 2015
  • Contact
    • Dictionaries - coming soon
    • L2:
  • Squid Game
  • Reflectico

STRINGS

Learners will be able to:
  • Know what a statement, strings and inputs are 
  • Code to enter data (strings) into the program
  • Apply these skills to develop a simple James Bond solution.

In this lesson you will learn about strings and how to use them in Python.  You can enter them and manipulate them and also change and replace them and a whole load of other tricks.

Part 1: Print, your first program:
  1. Run the code below, what does it do?
  2. The print is know as a 'statement' and prints what every is between the parenthesis.
  3. Make a code to print out your name, age and favorite food.
Strings:
Every letter, digit, and punctuation mark is a character. There are also many characters that are invisible on screen, such as the space, tab, and carriage-return characters.  Most programming languages provide a data type called 'character' or 'char', each value represents a single character from a predefined set, such as ASCII or Unicode. Each character has its own binary pattern.  Most programming languages have a data type called a string, which is used for data values that are made up of ordered sequences of characters, such as "hello world". A string can contain any sequence of characters, visible or invisible, and characters may be repeated. The number of characters in the string is called its length, and "hello world" has length 11 - made up of 10 letters and 1 space. There is usually a restriction on the maximum length of a string. There is also such a thing as an empty string, which contains no characters - length 0.  A string can be a constant or variable. If it is a constant, it is usually written as a sequence of characters enclosed in single or double quotation marks, ie 'hello' or "hello"

Part 2: raw_input:
  1. Sometimes you want the user to enter or input data in and can use the 'raw_input' code to enable this, run the program below.
  2. Adapt the code so that it prints out your name
  3. Can you alter the code so that the program says Hello to you?
  4. Create program which asks the user questions
Part 3: Strings are not numbers they do not have values:
  1. A string is a technically a code stored in memory that represents a symbol or a letter or number. It does not have a value.
  2. Don't believe me?, run the code below, what happens, why?
  3. So how do you get it to work properly?
  4. What about if you want to get the user to add a number of their choice, can you use raw_input?
  5. Add another code line to allow the user to add another number like line 6
  6. If raw_input does not work what can you use? (int, input, you may need to use IDLE)
Part 4: Strings can do this:
  1. You can create a number of variables at once with either string values or values, run the code below for an example.
  2. Can you create a program with 3 or even 4 variables?
  3. Change the operator (+, -, /, *) to make a new sum.
  4. Remove the ### on line 9 and run, what happens?
  5. The % can be used in place of the variables
  6. You can use variables instead but it is very chewy, can create the same line as line 9 but use variables instead, (clue..."dfdf", + "sdjhs")​​
Mr Bond!:
  1. Mr Bond is in trouble, watch the video evidence below:
  2. Can you use Python to recreate the seen, what will happen to Mr Bond?​
  3. You may want to use conditionals to give Mr Bond some options?
  4. Add some ASCII art to make the encounter more exciting.
  5. Compare your code with another student, what is different and why?
Try some of these string codes:
Homework
String Theory
File Size: 249 kb
File Type: pdf
Download File

Edit version
File Size: 34 kb
File Type: docx
Download File

Please complete this online quiz
Powered by Create your own unique website with customizable templates.
  • HOME
    • Yr 6
    • Revision
    • Class of 2017
    • COVER LESSON FB
    • Yr 10: Program of Study 2016
    • Yr 11:Coming soon
    • Student Showcase
  • KS3
    • Term 6: Databases
    • Term 5 Scratch
    • Term 4 Websites
    • Term 3 Spreadsheets
    • Term 2: Binary & Algorithms
    • Term 1: Basics and Hardware
  • J277/01 NEW
    • EPIC FAILS
    • Intro Lessons
    • 1.1 System Architecture >
      • 1.1.1: The CPU
      • 1.1.1: Parts of the CPU
      • 1.1.2: The CPU in action
      • CPU Recap Lesson
      • Little Man Computer
      • 1.1.3: Embedded Systems
      • RISC & CISC
      • End of Unit Exam
    • 1.2 Memory and Storage >
      • 1.2.1: Primary Storage (Memory)
      • Intro to Units of Memory
      • 1.2.2 Secondary Storage
      • How stuff works
    • 1.2.3 Units & Data Capacity
    • 1.2.4 Data Storage >
      • 1.2.4 Binary Conversion
      • 1.2.4 Binary Addition
      • L4: Hexadecimal
      • L5: Recap
      • L6: Characters
      • L7: Images
      • L8: SenseHAT images
      • L9: Sound & Sampling
      • L10: Code Sound
      • L11: Compression Part 1
      • L12: Compression Part 2 >
        • Compression
      • What do you know?
  • J276/02 old
    • Unit 2 Overview
    • 2.1 Algorithms >
      • L1: Intro to Algorithms
      • L2: The Knight's Tour
      • L3: Bresenham
      • L4: Searching Algorithms
      • L5: Bubble Sort
      • L6: Insertion Sort
      • L7: Merge
      • L8: Sorting Recap
      • L9: Creating Algorithms
      • L10: Pseudocode
      • L11: Interpreting Algorithms
      • L12: End of Unit Test
    • 2.2 Programming Techniques >
      • Coding Intro
      • L1: Programming Concepts
      • L2: Sequence, Selection & Iteration
      • L3: SSI Practice
      • L4: String Manipulation
      • L5: Secret Codes
      • L6: File Handling
      • L7: Use of records to store data
      • L8: SQL
      • L9: SQL Python
      • L10 ,11, 12: Arrays
      • L13: Functions
      • L14: Data Types
      • L15: Casting
      • L16 -17: Test and Code
    • 2.3 Robust Programs >
      • L1 : Defensive Design
      • L2 : Testing Programs
    • 2.4 Computational Logic >
      • L1: Comp. Logic 1
      • L2: Comp. Logic 2
      • L3: Operators (Python)
    • 2.5 Translators & Language >
      • L1: Types of Languages
      • L2: Translators
  • Yr 9
    • Year End Examination
    • iMedia 5: Comics
    • iMedia 4: School Brochure
    • iMedia 3: Presentations
    • iMedia 2: Review and Mail Merge
    • iMedia 1: IT Letter Writing
    • L10: Intro to iMedia
    • L9 Building a Computer
    • L8: Buying a House
    • L7: Logic Gates
    • L6: Binary
    • L5: CS Alan Turing
    • L4: Spreadsheets
    • L3: JS in an Hour!
    • L2: Intro to Coding
    • L1: CS Compression
  • Py
    • Coding Concepts
    • Writing your first Program
    • Python Pages
    • Python Playground
    • Strings
    • Python Operators
    • Functions
    • Conditions
    • Try and Except
    • Break and Continue
    • Odd codes
  • Py +
    • Looping
    • Why does my code not work?
    • Errors
    • Validation
    • Lists
    • Lists again
    • Looking for data in String
    • Writing to Files
    • Read, Write & Sorting Data
  • CODING
    • Magic Python
    • Alan Turing
    • Brian the Turtle
    • Grade Calculator
    • Nested IF Hotels
    • Vending Machine
    • A Looping Menu
    • For
    • Christmas Coding
    • JS in an Hour!
    • CSS + HTML
    • Medical Claims
    • Hour of Code 2015
  • Contact
    • Dictionaries - coming soon
    • L2:
  • Squid Game
  • Reflectico