0% found this document useful (0 votes)
5 views5 pages

03 Lists Basics Lab

The document outlines a lab assignment involving basic list operations in programming. It includes four tasks: rearranging animal body parts, creating a list of courses, separating positive and negative integers, and filtering strings based on a keyword. Each task provides input-output examples and hints for implementation.

Uploaded by

fetata89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

03 Lists Basics Lab

The document outlines a lab assignment involving basic list operations in programming. It includes four tasks: rearranging animal body parts, creating a list of courses, separating positive and negative integers, and filtering strings based on a keyword. Each task provides input-output examples and hints for implementation.

Uploaded by

fetata89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab: Lists Basics

Please, submit your source code solutions for the described problems to the Judge System.

1. Strange Zoo
You are at the zoo, and the meerkats look strange.
You will receive 3 strings on separate lines, representing the tail, the body, and the head of an animal in that order.
Your task is to re-arrange the elements in a list so that the animal looks normal again:
 On the first position is the head;
 On the second position is the body;
 On the last one is the tail.

Example
Input Output
my tail ['my head is on the wrong end!', 'my body
my body seems on place seems on place', 'my tail']
my head is on the wrong end!
tail ['head', 'body', 'tail']
body
head
T ['H', 'B', 'T']
B
H

Hints
We start by reading the three parts of the body:

Then, we create a list containing those three elements:

We swap the elements and print the list:

2. Courses
On the first line, you will receive a single number n. On the following n lines, you will receive names of courses. You
should create a list of courses and print it.

Example
Input Output

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 5


2 ['PB Python', 'PF Python']
PB Python
PF Python
4 ['Front-End', 'C# Web', 'JS Core',
Front-End 'Programming Fundamentals']
C# Web
JS Core
Programming Fundamentals

Hints
We read the number n from the console, and we create an empty list:

Then, we create a loop that reads each course and adds it to the list:

Finally, we print the list:

3. List Statistics
On the first line, you will receive a number n. On the following n lines, you will receive integers. You should create
and print two lists:
 One with all the positive (including 0) numbers
 One with all the negative numbers
Finally, print the following message:
"Count of positives: {count_positives}
Sum of negatives: {sum_of_negatives}"

Example
Input Output
5 [10, 3, 2]
10 [-15, -4]
3 Count of positives: 3
2 Sum of negatives: -19
-15
-4
6 [11, 2, 35, 599, 31, 20]
11 []
2 Count of positives: 6
35 Sum of negatives: 0
599

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 5


31
20

Hints
We start by reading the number n:

Then, we create a loop that reads the current number and checks if it is positive or not:

 If it is, we add it to the list of positive numbers.


 If it is not, we add it to the list of negative numbers.
Then we print the three lines:

 To get the count of the positives, we can use the len function.
 To get the sum of the negatives, we can use the sum function.

4. Search
On the first line, you will receive a number n. On the second line, you will receive a word. On the following n lines,
you will be given some strings. You should add them to a list and print them. After that, you should filter out only
the strings that include the given word and print that list too.

Example
Input Output
3 ["I study at SoftUni", "I walk to work", "I
SoftUni learn Python at SoftUni"]
I study at SoftUni ["I study at SoftUni", "I learn Python at
I walk to work SoftUni"]
I learn Python at SoftUni
4 ["I love tomatoes", "I can eat tomatoes
tomatoes forever", "I don't like apples", "Yesterday
I love tomatoes I ate two tomatoes"]
I can eat tomatoes forever ["I love tomatoes", "I can eat tomatoes
I don't like apples forever", "Yesterday I ate two tomatoes"]
Yesterday I ate two tomatoes

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 5


Hints
We start by reading the number n and the word we would search for. Then, we create our empty list:

We create a loop that adds all the strings to our list. After that, we print it:

Finally, we create another loop to remove the strings we do not need by iterating through the strings reversed (so
we don't skip elements when removing) and print the list again:

5. Numbers Filter
On the first line, you will receive a single number n. On the following n lines, you will receive integers. After that, you
will be given one of the following commands:
 even
 odd
 negative
 positive
Filter all the numbers that fit in the category (0 counts as a positive and even). Finally, print the result.

Example
Input Output
5 [-2, 18,
33 998]
19
-2
18
998
even
3 [-4]
111
-4
0
negativ
e

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 5


Hints
First, we read the number n. Then, we create the numbers list and the filtered list:

We create a loop that reads all the numbers and adds them to the list:

Then, we read the command and check for all the cases:

Finally, we print the filtered list.

© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 5 of 5

You might also like