Algo DombitLearn by building
Loading your work...
Python - Lesson 2 - Variables

Name it. Store it.
Use it again.

Learn variable assignment, valid names, multiple assignment, input(), and len().

name, age, group = "Aziza", 15, "Python-2"
What you will practise
  • Assign and update values
  • Recognise valid Python names
  • Use multiple assignment safely
  • Save input and length results
Remember
  1. = means assign.
  2. input() gives you a string.
  3. Spaces count in len().
  4. Names are case-sensitive.
Part A

Variable assignment

Follow each assignment in order and write the exact output.

12 points

1One variable

x = 5
print(x)

2Update a value

points = 10
points = points + 5
print(points)

3A string value

city = "Tashkent"
print(city)

4Copy, then change

x = 2
y = x
x = 8
print(y)

5Different data types

name = "Ali"
age = 15
print(name, age)

6Store a length

word = "Python"
size = len(word)
print(size)

7Write an assignment

Create a variable named score and assign the integer 27.

Partial result

Check this part without submitting the full homework.

Part B

The boring-but-important naming rules

Choose whether each name is valid Python syntax.

10 points

1student_name

Variable name

22students

Variable name

3score2

Variable name

4first-name

Variable name

5_class

Variable name

6class

Variable name

7user name

Variable name

8TOTAL

Variable name

9myVariable

Variable name

10len

Variable name
Important len is syntactically valid, but using it as your own variable hides Python's built-in len() function. Avoid it.
Partial result

Check this part without submitting the full homework.

Part C

Multiple assignments

The number of names and values must match.

12 points

1Three values

x, y, z = 1, 2, 3
print(x, y, z)

2Custom separator

x, y, z = 1, 2, 3
print(x, y, z, sep="-")

3A mixed assignment

name, age, score = "Aziza", 15, 92.5
print(name, age, score)

4Swap two values

a, b = 4, 9
a, b = b, a
print(a, b)

5One value, three names

x = y = z = 7
print(x + y + z)

6Count carefully

x, y = 1, 2, 3

Will this assignment run?

Result
Partial result

Check this part without submitting the full homework.

Part D

input() and len()

Remember that input returns text and len counts every character.

16 points

Quick type check

What type does input() return when the user enters 42?

Result type

2Count a short name

name = input()
print(len(name))

Input: Ali

3Spaces count too

school = input()
print(len(school))

Input: Dombit School

4An empty input

text = input()
print(len(text))

Input: (empty line)

5Two inputs

first = input()
last = input()
print(first, last, sep="_")

Input: Ali / Vali

6Store the result

word = input()
length = len(word)
print("Length:", length)

Input: Python

7City and country

Read a city, then a country. Print both values on one line.

8Nickname length

Read a nickname and print Your name has N characters.

Partial result

Check this part without submitting the full homework.

Programs

Build three small programs

Combine variables, multiple assignment, input(), and len().

50 points
Program 1

Dombit Student Badge

student_badge.py

Input

Aziza
Python-2

Required output

Student: Aziza
Group: Python-2
School: Dombit
Name length: 5
  • Read name and group
  • Assign school = "Dombit"
  • Use len(name)
  • Do not hard-code Aziza or Python-2
Program 2

Three-Word Unpacker

three_words.py

Input

Red
Green
Blue

Required output

Red | Green | Blue
  • Use one multiple-assignment statement
  • Call input() three times
  • Use sep=" | "
  • Print the three variables in order
Program 3

Secret Codename

secret_codename.py

Input

Ali
Vali
7

Required output

Codename: Ali_Vali_7
Length: 10
  • Read three inputs
  • Store the joined text in codename
  • Use underscores between values
  • Print len(codename)

Reflection

Which variable name rule is easiest to forget? Explain how input() and len() work together.

Partial result

Check this part without submitting the full homework.

Lesson 02

Ready to finish?

Complete every required answer, check each section, then mark Lesson 2 as finished.