Computer science
  • Exam boards
    • OCR past papers >
      • Paper1 (Sample)
    • Edexcel past papers >
      • 2020 Current spec (coming soon) >
        • Programming Language Subset (PLS)
      • Old 2016 SPEC >
        • Paper 1 (specimen1)
        • Paper 1 (specimen2)
        • Paper 1 (2018)
        • Paper 1 (2019)
        • Paper 2 (specimen1)
        • Paper 2 (2018)
        • Paper 2 (2019)
      • OLD 2013 SPEC >
        • Sample assessment 1 (old spec)
        • Sample assessment 2 (old spec)
        • June 2017 (old spec)
        • June 2016 (old spec)
        • June 2015 (old spec)
    • Paper 1 (by topic) >
      • Algorithms
      • Application software
      • Ascii
      • Binary
      • Cache
      • Client Server
      • Cloud
      • Compression
      • Computational thinking
      • CPU
      • Cyber security
      • Database
      • Fetch decode execute cycle
      • Embedded system
      • Encryption
      • File size
      • Flow chart
      • Hexadecimal
      • High Level language
      • ISP/Internet
      • Logic
      • Magnetic HDD
      • Networking
      • Open source
      • Operating system
      • Peer to peer
      • Images (Data representation)
      • Protocols
      • RAM
      • ROM
      • Run length encoding
      • Simulation software
      • Solid state HDD
      • Sound
      • Stored program concept
      • Utility software
    • Curriculum >
      • Binary
      • Hex
      • Data Representation
      • Compression
      • Encryption
      • What is a computer
      • How does a computer work
      • Hardware
      • Operating system
      • The CPU
      • Input devices
      • Data storage
      • Networks
      • Microcontrollers
      • Computational models
      • Emerging trends
      • Virtual machine
      • Models and simulators
      • Algorithms
    • Python >
      • Finding python
      • GCSE Python questions
      • Python coding >
        • Comments
        • Data types
        • Variables
        • If Else
        • If Elif Else
        • Functions
        • For loop
        • While loop >
          • While loop challenges
        • Data structures >
          • Looping thru 2D array
        • String slicing/indexing
        • Subprograms
        • Local/global variable
        • Validation and try
        • methods
        • File I/O
        • Pseudocode
        • Modules >
          • Turtle
        • Classes
        • NEA/Projects
  • KS3/Other
    • KS3 >
      • Online Safety >
        • Screen time
        • Online Safety questions
      • IT >
        • Word
        • PowerPoint
      • Hardware >
        • All Hardware
        • Magnetic hard disk drive
        • Optical disk drive
        • Solid state drive
      • Software
      • Binary/Hex/Algorithms >
        • Binary
        • Binary explained
        • Hexadecimal - 1 digit
        • Hexadecimal - 2 digits
        • Algorithms
        • ASCII
        • Tests
      • Networks
      • Protocols/Cyber attacks
      • Logic >
        • CPU
        • AND gate
        • OR gate
        • NOT gate
        • Logical statements
      • Coding >
        • HTML
        • Scratch >
          • Scratch questions
        • Python >
          • Getting started
          • Functions
          • Variables
          • VariablesToo
          • inputs
          • Selection
          • Flowcharts
          • Data types
          • Pseudocode1
          • Pseudocode2
          • Subprogram1
          • Subprogram2
          • Coding challenges
    • BTEC CS
    • OCR GCSE CS >
      • Past paper JUNE 2015
      • Past paper June 2014
      • Past paper MAY 2012
      • Past paper JAN 2011
      • Past paper JUN 2011
    • AQA AS-Level CS >
      • AS Curriculum >
        • Multiple choice questions
    • Business studies >
      • Keywords
      • BS Revision - Multiple choice
      • Paper 1 (9-1)
      • Paper 2 (9-1)
  • Contact/More
    • Code editor
    • Contact us
    • Microbit ideas
    • More
  • Self test
    • 01 Random topics
    • 02 Programming
    • 03 Data
    • 04 Computers
    • 05 Networks
    • 06 Legal/Ethics/Enviro'
    • Coding/Programming

Python coding

PYTHON DICTIONARY


Comments

Data types

Variables

If Else

If Elif Else

Functions

For loop

While loop

Data structures

String slicing

User defined function

Local/Global variable

Validation and Try

Methods

​File I/O

Pseudocode

Modules​

What is a function?

The people who created the Python language decided to create some shortcuts for the people who will use it to code. The shortcuts allow us code for certain aspects quicker. For example, to display some text to the screen, you can use the print() function.

The print() function is an example of a"built in" function. Not only can you use the built in Python functions, but you can also create your own (these are called user defined functions).

​A function is a piece of code that can be used over and over again.

Picture

What functions do i need to know?

As many as possible, but here is a list of functions that you will find useful:

Function
Description
print()
Displays text on the screen
input()
Prompts a user to enter data via the keyboard (also displays text on the screen)
int()
Specifies that the data you want is an integer (whole number)
str()
Specifies that the data you want is an string (letter, number or character)
float()
Specifies that the data you want is an float (number with a decimal)
help()
Built in help system. Use it in shell e.g. help(print)
len()
Tells you the length of an object. e.g. in shell try len("duuude")
type()
Tells you the type of object. e.g. in shell try type(1) or type(1.1)
range()
Allows a range of number to be used. Used frequently with a For loop
list()
Can take a string and covert it to a list

Python challenge - print() function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
Change both instances of "FastFood" to "BestFriend" and then change "KFC" to the name of your best friend. What happens now? The print() function allows for data to be displayed to the screen


Python challenge - input() function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
Can you enter a combination of letters, numbers and symbols?


​Python challenge - float()​ function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
In this code, you are asking someone to the price of a song on Itunes  BUT you are specifying that the data they enter is a float().  Why do we generally express prices as a float and not an int? (also we are using the function input() which displays the question on the screen and prompts the user to enter information using the keyboard

Python challenge - int()​ function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
In this code, you are asking someone to enter their age BUT you are specifying that the data they enter is an int() or Integer.  Why do we generally express how old we are as an int and not a float? (also we are using the function input() which displays the question on the screen and prompts the user to enter information using the keyboard

​Python challenge - str()​ function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
In this code, you are asking someone to enter their name BUT you are specifying that the data they enter is an str() or string.  Why do we generally express how old we are as a string and not an int? (also we are using the function input() which displays the question on the screen and prompts the user to enter information using the keyboard

​Python challenge - help() function

Enter the following code in a Python SHELL and press enter
Picture
What happens? Now, in the brackets, type any of the function e.g. help(int) or help(str). What is being displayed? Is this useful to you?

​Python challenge - len() function

Enter the following code in a Python SHELL and press enter
Picture
What happens? Run it again but change the string

​Python challenge - type() function

Enter the following code in a Python SHELL and press enter
Picture
What happens? Run it again but change the data type

​Python challenge - range() function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
What happens? Change the value of 10 to 20 and see what is happens. Now in the brackets put the following values (5,10) and see what happens. Now in the brackets put the following values (2,26,2) and see what happens. Now in the brackets put the following values (3,39,3) and see what happens. Can you explain what the values in the brackets are doing?

Python challenge - round() function

Enter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Picture
What happens?  What if you change the the (, 2)to (, 3)?
Home
Contact
Upload
Log in
  • Exam boards
    • OCR past papers >
      • Paper1 (Sample)
    • Edexcel past papers >
      • 2020 Current spec (coming soon) >
        • Programming Language Subset (PLS)
      • Old 2016 SPEC >
        • Paper 1 (specimen1)
        • Paper 1 (specimen2)
        • Paper 1 (2018)
        • Paper 1 (2019)
        • Paper 2 (specimen1)
        • Paper 2 (2018)
        • Paper 2 (2019)
      • OLD 2013 SPEC >
        • Sample assessment 1 (old spec)
        • Sample assessment 2 (old spec)
        • June 2017 (old spec)
        • June 2016 (old spec)
        • June 2015 (old spec)
    • Paper 1 (by topic) >
      • Algorithms
      • Application software
      • Ascii
      • Binary
      • Cache
      • Client Server
      • Cloud
      • Compression
      • Computational thinking
      • CPU
      • Cyber security
      • Database
      • Fetch decode execute cycle
      • Embedded system
      • Encryption
      • File size
      • Flow chart
      • Hexadecimal
      • High Level language
      • ISP/Internet
      • Logic
      • Magnetic HDD
      • Networking
      • Open source
      • Operating system
      • Peer to peer
      • Images (Data representation)
      • Protocols
      • RAM
      • ROM
      • Run length encoding
      • Simulation software
      • Solid state HDD
      • Sound
      • Stored program concept
      • Utility software
    • Curriculum >
      • Binary
      • Hex
      • Data Representation
      • Compression
      • Encryption
      • What is a computer
      • How does a computer work
      • Hardware
      • Operating system
      • The CPU
      • Input devices
      • Data storage
      • Networks
      • Microcontrollers
      • Computational models
      • Emerging trends
      • Virtual machine
      • Models and simulators
      • Algorithms
    • Python >
      • Finding python
      • GCSE Python questions
      • Python coding >
        • Comments
        • Data types
        • Variables
        • If Else
        • If Elif Else
        • Functions
        • For loop
        • While loop >
          • While loop challenges
        • Data structures >
          • Looping thru 2D array
        • String slicing/indexing
        • Subprograms
        • Local/global variable
        • Validation and try
        • methods
        • File I/O
        • Pseudocode
        • Modules >
          • Turtle
        • Classes
        • NEA/Projects
  • KS3/Other
    • KS3 >
      • Online Safety >
        • Screen time
        • Online Safety questions
      • IT >
        • Word
        • PowerPoint
      • Hardware >
        • All Hardware
        • Magnetic hard disk drive
        • Optical disk drive
        • Solid state drive
      • Software
      • Binary/Hex/Algorithms >
        • Binary
        • Binary explained
        • Hexadecimal - 1 digit
        • Hexadecimal - 2 digits
        • Algorithms
        • ASCII
        • Tests
      • Networks
      • Protocols/Cyber attacks
      • Logic >
        • CPU
        • AND gate
        • OR gate
        • NOT gate
        • Logical statements
      • Coding >
        • HTML
        • Scratch >
          • Scratch questions
        • Python >
          • Getting started
          • Functions
          • Variables
          • VariablesToo
          • inputs
          • Selection
          • Flowcharts
          • Data types
          • Pseudocode1
          • Pseudocode2
          • Subprogram1
          • Subprogram2
          • Coding challenges
    • BTEC CS
    • OCR GCSE CS >
      • Past paper JUNE 2015
      • Past paper June 2014
      • Past paper MAY 2012
      • Past paper JAN 2011
      • Past paper JUN 2011
    • AQA AS-Level CS >
      • AS Curriculum >
        • Multiple choice questions
    • Business studies >
      • Keywords
      • BS Revision - Multiple choice
      • Paper 1 (9-1)
      • Paper 2 (9-1)
  • Contact/More
    • Code editor
    • Contact us
    • Microbit ideas
    • More
  • Self test
    • 01 Random topics
    • 02 Programming
    • 03 Data
    • 04 Computers
    • 05 Networks
    • 06 Legal/Ethics/Enviro'
    • Coding/Programming