Search Header Logo
Variables in Python

Variables in Python

Assessment

Presentation

Computers

8th Grade

Practice Problem

Hard

Created by

Khawla Hijazi

Used 35+ times

FREE Resource

9 Slides • 4 Questions

1

Variables In Python

2

Definition and Usage

  • The input() function allows user input.

  • For Example:

If you need to ask the user a question and you expect the user to enter a value.

Like

what is you name?

Or

What is your age?

Or

Enter your birthdate

3

Syntax

Input (prompt)

4

Input(prompt)

Syntax

media

5

Example

  • Write a python program to ask the user about their favorite Drink then print the answer “ My favorite drink is …………”

  1. First:

Declare a variable to store the answer inside it

 Drink=input(“what is your favorite drink?”)

  1. Write the print command to print the answer

Print(“My favorite drink is “+ Drink)

6

Multiple Choice

Which of the following statements are correct?

1

Variables varies depending on the circumstances

2

Variables cannot be changed

3

Variables can be changed

7

colour=“brown ”

animal=“dog”

print(colour+animal)

Example:

A variable is created the moment you first assign a value to it.

How to declare a variable in Python

8

Single or Double Quotes?

String variables can be declared either by using single or double quotes:
Example:
Student_name="Ahmad"
or
Student_name='Ahmad'

9

Variable Names

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:

  • A variable name must start with a letter or the underscore character

  • A variable name cannot start with a number

  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

  • Variable names are case-sensitive (age, Age and AGE are three different variables)

  • A variable name cannot be any of the Python keywords.

10

Multiple Select

Choose the correct variable name:

1

First Student

2

FirstStudent

3

1Student

4

First_Student

11

Multiple Choice

Is variable name CarName is the same as carname?

1

True

2

False

12

Fill in the Blanks

13

Use variable practice

Write a pythoin programe using variables to print Welcome yourname :

1. declare the variable

Name="khawla"

2. write the print sentence:
print("welcome " + Name)

The + is used for concatenation ( to combine strings together)

Variables In Python

Show answer

Auto Play

Slide 1 / 13

SLIDE