
01 Python Basics
Presentation
•
Computers
•
University
•
Practice Problem
•
Medium
Karen Ahmed
Used 138+ times
FREE Resource
14 Slides • 11 Questions
1
Python Programming
Lesson 1: Python Basics
2
Using Python
Python runs in an Integrated Development Environment (IDLE)
Python provides a Python Shell, which can be used to execute single Python commands and display the result.
3
Creating Programs
We need to create a new file to write our Python programs.
This will be a blank text file which is saved as a .py document (a Python file type)
4
Print & Comments
The print() function will display a message to the shell
The message to be printed needs to be in brackets surrounded by quotes
Double or single quotes can be used, but it is important to remain consistent!
Comments in Python begin with the # character.
Before we can run Python code, we must first save the file.
Run the code by selecting Run>Run Module from the menu.
5
Multiple Choice
Which function outputs text to the terminal?
write()
print()
output()
type()
6
Variables
We need to create variables to store values
In Python, we assign variables by using the equals sign =
Variables cannot have any spaces or symbols in their names other than an underscore.
Variable names cannot being with numbers, but they can have numbers after the first letter.
In Python, we do not have to specify a data type for our variables when we declare them.
The basic data type are int, float and string
7
Multiple Choice
Which of the following will produce a Syntax Error?
answer = "This is an error"
answer = this_is_an_error
answer = "This is an error'
All of them
8
Multiple Choice
What is the Python syntax for creating a variable and assigning the number 10 to it?
def variable_name = 10
variable_name == 10
variable_name = 10
int variable_name = 10
9
Multiple Choice
Which character is used to specify a comment in Python?
"
*
/
#
10
Arithmetic Operations
When we perform division, the result has a decimal place.
This is because Python converts all ints to floats before performing division.
In older versions of Python (2.7 and earlier) this conversion did not happen and integer division would always round down to the nearest integer.
Performing arithmetic does not change the value of a variable, you can only update values using the = sign.
11
Multiple Choice
What will get printed if we run this code?
6
10
12
Multiple Choice
Now what will get printed?
6
10
13
String Concatenation
The + operator does not just add two numbers
It can also “add” two strings
The process of combining two strings is called string concatenation
Performing string concatenation creates a brand new string comprised of the first string’s contents followed by the second string’s contents
Concatenation does not include spaces between the strings!
14
str()
To concatenate a string with a number, we need to convert the number into a string first.
We do this using the str() function.
We do not need to convert a number to a string for it to be an argument in a print statement.
15
Multiple Choice
How do you combine two strings?
string1.concatenate(string2)
string1.string2
string1.combine(string2)
string1 + string2
16
Plus Equals
Python offers a shorthand for updating variables.
When you have a number saved in a variable and want to add to the current value of the variable, you can use the += (plus-equals) operator.
We can also use the plus-equals operator for string concatenation.
17
Multiple Choice
What is the value of total_cost that gets printed?
15
10
5
18
User Input
We can output a value using print()
We can assign data to a variable using input()
The input() function requires a prompt message, which it will print out for the user before they enter their data.
For example:
Python always accepts user input as a string!
19
Multiple Choice
What is printed when we run this code if the user enters the values 5 and 6?
11
56
20
Strings to Ints
If we want to work with numbers, for example integers, we need to convert the users input to an integer.
We can do this using the int() function.
Now the program will work as expected.
21
Multiple Choice
What is the output of this code?
210
42
cool_number
22
Multiple Choice
What happens if you run this code?
"message" is printed
"What a cool message!" is printed
Python throws a SyntaxError
23
Exercise 1
ASCII art is a graphic design technique that consists of pictures made up of individual characters.
Write a Python program called initials.py that displays the initials of your name in block letters.
24

ascii-art - Replit
You can open this webpage in a new tab.
25

LovelyLoveseats - Replit
You can open this webpage in a new tab.
Python Programming
Lesson 1: Python Basics
Show answer
Auto Play
Slide 1 / 25
SLIDE
Similar Resources on Wayground
18 questions
Computing Facts & Knowledge
Presentation
•
University
20 questions
Part of computer
Presentation
•
KG
20 questions
วิชาการเขียนโปรแกรมภาษา C
Presentation
•
KG - University
18 questions
Robotica aplicada en la educacion
Presentation
•
University
19 questions
INGLES 1 - Sesión 2 Greetings and Farewells
Presentation
•
University
19 questions
General Interview Question
Presentation
•
University
20 questions
Presentation tips
Presentation
•
University
20 questions
An introduction to ReactJS State
Presentation
•
University
Popular Resources on Wayground
20 questions
STAAR Review Quiz #3
Quiz
•
8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
6 questions
Marshmallow Farm Quiz
Quiz
•
2nd - 5th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
12 questions
What makes Nebraska's government unique?
Quiz
•
4th - 5th Grade