There are two lists a
and b
(see below).
a
, the third element of a
, and the last element of a
.b
a number 7 (just write to the end).a
to 8.merged
, that includes all the elements of a
and of b
.c
that can be obtained by changing the last element of a
to 100. The list a
should not be changed!a = [1, 0, 9, 12, 18, 34, 89, 91, 33, 127]
b = [2, 8, 9, 11, 76, 25, 44]
There is a list of names:
girls = ["Ivetta", "Violetta", "Cassandra",
"Viktoria", "Amelia", "Rose", "Elizabeth"]
Using girls
, print the following lists:
["Violetta", "Cassandra", "Viktoria", "Amelia"]
["Viktoria", "Amelia", "Rose", "Elizabeth"]
["Ivetta", "Violetta", "Viktoria", "Amelia"]
["Cassandra", "Amelia", "Rose"]
We have the list L
. Print (one element from a new line):
L
;L
.L = [12, 3, 8, 125, 10, 98, 54, 199]
Change the fifth element of L
to 0. Do the same operations as above. Why do you get such results?
In the list age
we store respondents' age:
age = [24, 35, 42, 27, 45, 48, 33]
Create the list age2
with values of respondents' age squared.
Hint: use a for-loop.
Python asks a user to enter an integer number $k$ from 1 to 10. Python takes this value $k$ and prints the $k$-th element of the list numbers
, assuming that the numeration starts from 1.
numbers = [1, 5, 6, 8, 10, 21, 25, 1, 0, -9, 9]
Example:
Input:
Enter an integer from 1 to 10: 3
Output:
6
Explain, what the following code does and why it returns such results:
l = [1,2,3,4]
for i in range(len(l)):
a = l[i] + l[i-1]
print(a)
5 3 5 7