Download presentation
Presentation is loading. Please wait.
1
Design & Technology Grade 7 Python
Python Introduction
2
Input Date Processing Out Put Information Program Editor Compiler
Problem Programmer Algorithm flowchart Program Editor Compiler Real Program Run Input Date Processing Out Put Information
3
Python is a programming Language Python = Program (Script ) is list of instructions or statements Statement = Syntax (Format ) Syntax = Spelling & Grammar
4
Displaying String Output
String output: A message appears onscreen that consists of a series of text characters. Print statement ( syntax ) Format: print ("the message that you wish to appear")
5
Print (“I love “ + “ Python “)
The Print Statement To Display output Print ( constant ) Print (“ string “ ) Print (Expression ) Print ( Mixed ) Print ( variable ) Print (5) Print (“Python”) Print ( 5+6) Print (“I love “ + “ Python “) Print (5, “ICT”,1+2)
6
Arithmetic Operators Operator Description Example = Assignment num = 7
+ Addition num = 2 + 2 - Subtraction num = 6 - 4 * Multiplication num = 5 * 4 / Division num = 25 / 5 % Modulo num = 8 % 3 ** Exponent num = 9 ** 2 num = 9//2 divide //
7
Parenthesis ( ) Power ** Multiplication * , / Addition + , -
Order Of Operation Parenthesis ( ) Power ** Multiplication * , / Addition , - Left to Right
8
Variables Format: Examples: Num = 5 X =2.3 Firstname = “Basma”
<name of variable> = <Information to be stored in the variable> Examples: Num = 5 X =2.3 Firstname = “Basma”
9
Variables Naming Must start with a letter Case Sensitive
Can’t be Python Key word Prefer Meaningful capitalizing the first letter of each word
10
Variables Naming Myage = 5 FirstName =“Basma” HourWork=8
RateperHour=50 Side_Squar=10
11
Input Statement The computer program getting string information from the user. Strings cannot be used for calculations (information getting numeric input will provided shortly). Format: <variable name> = input("<Prompting message>") Example: name = input ("What is your name: ") Print ( name )
12
Converting Between Different Types Of Information (2)
Example motivation: you may want numerical information to be stored as a string (for the formatting capabilities) but also you want that same information in numerical form (in order to perform calculations). Some of the conversion mechanisms available in Python: Format: int (<value to convert>) float (<value to convert>) str (<value to convert>) Examples: Program name: convert1.py x = 10.9 y = int (x) print (x, y)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.