Search Header Logo
Procedural Programming: 01 Python Basics

Procedural Programming: 01 Python Basics

Assessment

Presentation

Computers

University

Practice Problem

Medium

Created by

Karen Ahmed

Used 22+ times

FREE Resource

12 Slides • 9 Questions

1

Procedural Programming: Lesson 1 Part 2

Python Basics

media

2

​Statements & Expressions

  • ​Python is an interpreted high-level programming language.

  • ​A complete computer command is called a statement.

  • ​For example: print("Hello World")

  • ​An expression evaluates to a new value.

  • ​For example: 2*2

media

3

Multiple Choice

What is a statement?

1

A section of an algorithm

2

A translation of machine code

3

A precise description of a problem

4

A complete computer command

4

Multiple Choice

Which function outputs text to the terminal?

1

output()

2

print()

3

write()

4

type()

5

​Variables

  • ​We can store values in variables.

  • ​To do this we use the assignment operator =

  • For example: answer = 2*2

  • ​Variables store values not expressions

  • ​Good variable names describe the data they contain

6

Multiple Choice

How do we assign the number 10 to a variable?

1

new variable_name = 10

2

variable_name == 10

3

def variable_name = 10

4

variable_name = 10

7

Multiple Choice

Question image

What is the output of this code?

1

cool_number

2

210

3

42

8

​Data Types

  • All variables have a data type

  • ​ints are whole numbers

  • ​floats are decimal numbers

  • ​strings are text

  • ​Variables can be of any data type

  • ​In Python, we don't need to declare variables, we can just use them by assigning a value

  • ​For example:

media

9

Multiple Choice

Question image

Which of these variables is a string?

1

cool_variable_1

2

cool_variable_2

3

cool_variable_3

4

cool_variable_4

10

Multiple Choice

What is the difference between a float and an int?

1

A float is text, int is a number

2

A float is decimal, int is a whole number

3

A float is a whole number an int is decimal

11

​Strings

  • ​We can define strings on multiple lines

  • We can combine string values to make a new string.

  • ​Strings are combined using the + operator.

  • This is called string concatenation.

  • Strings are concatenated without spaces.

media
media
media

12

Multiple Choice

How do we define a multi-line string?

1

###

Like this

###

2

***

Like this

***

3

"""

Like this

"""

13

Multiple Choice

How do you combine two strings?

1

string1 + string2

2

string1.combine(string2)

3

string1.concatenate(string2)

14

​Comments

  • We use comments to explain our code.

  • Comments are ignored by programming languages.

  • A comment in Python begins with the # character

  • For example: #this is a comment​

media

15

Multiple Choice

What character begins a comment in Python?

1

%

2

*

3

#

4

/

16

web page not embeddable

ascii-art - Replit

You can open this webpage in a new tab.

17

media

​Lovely Loveseat Project

18

web page not embeddable

LovelyLoveseats - Replit

You can open this webpage in a new tab.

19

​User Input

  • ​We can also use variables to store user input.

  • ​We use input() to assign a user value to a variable.

  • ​This requires a prompt message for the user.

  • ​This is printed before they can enter data.

  • ​For example:

media

20

​Working with Strings & Ints

  • ​Python always accepts user input as a string.

  • ​So we cannot perform calculations with it.

  • ​We need to convert the input string to an int using the int() function

  • ​For example:

media

21

web page not embeddable

TheCalculator - Replit

You can open this webpage in a new tab.

Procedural Programming: Lesson 1 Part 2

Python Basics

media

Show answer

Auto Play

Slide 1 / 21

SLIDE