The following exercises cover scenarios on variables in Python.
Exercise 1 – Assign variable
Create a variable named x
, and assign it a value of 20
.
=
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 2 – String variable
We have a variable named x
. Assign it a string value of "Hello World"
.
x = ""
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 3 – Assign multiple variables in a single line
Create two variables named x
and y
, and assign them with values 10
and 20
respectively.
, = ,
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 4 – Print variable
We have a variable named x
which is assigned a value of 'apple'
. Print the variable x
to standard output.
x = 'apple' print()
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 5 – Find sum
Assign variable x
with 10
, and variable y
with 20
. Find their sum and assign the result to a variable z
. Then print the variable z
.
x = y = = x + y print()
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.
Exercise 6 – Assign multiple variables with same value
Fill in the fields with correct syntax to initialize all the three variables x
, y
, and z
with the same value of 'apple'
in a single statement.
= = = 'apple'
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.