Introduction To Programming Week - 2
Introduction To Programming Week - 2
programming
This IPO approach involves, what the user must enter on the
keyboard and what processing or manipulations will be done.
Input, processing, and output
Input:
Data that the program receives while it is running
Perform some process on the input
Example: mathematical calculation
Produces output
Displaying output with the print function
• Function: piece of prewritten code that performs an
operation
• Print function: displays output on the screen
• Argument: data given to function
Example: data that is printed to screen
comments
Comment: notes of explanation within a program
o Ignored by python interpreter
o Intended for a person reading the program’s code
o Begin with a # character
End line comment: appears at the end of a line of code
o Typically explains the purpose of that line
variables
• Variable: name that represents a value stored in the computer
memory
• Used to access and manipulate data stored in memory
• A variable references the value it represents
• Assignment statement: used to create a variable and make it
reference data
• General format is variable = expression
• Assignment operator: the equal sign(=)
• Example: age=18
continue
• In assignment statement, variable receiving value must be on
left side
• Variable name should not be enclosed in quote marks
• Variable can only be use if a value is assigned to it
Variable naming rules
• Variable name cannot be a python key word
• Variable name cannot contain spaces
• First character must be a letter or an underscore
• After first character may use letter, digits, or underscores
• Variable names are case sensitive
Reading input from the
keyboard
• Most programs need to a read input rom the user
• Built-in input function reads input from keyboard
• Format: variable= input(prompt)
Prompt is typically a string instructing user to enter a value