0% found this document useful (0 votes)
9 views3 pages

Lists Basic

The document contains 10 Python programming questions focused on list manipulation, including creating lists, summing elements, accessing indices, sorting, reversing, counting occurrences, and concatenating strings. Each question includes a brief description and a sample answer demonstrating the required functionality. The exercises aim to reinforce fundamental programming concepts using Python lists.
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)
9 views3 pages

Lists Basic

The document contains 10 Python programming questions focused on list manipulation, including creating lists, summing elements, accessing indices, sorting, reversing, counting occurrences, and concatenating strings. Each question includes a brief description and a sample answer demonstrating the required functionality. The exercises aim to reinforce fundamental programming concepts using Python lists.
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/ 3

Here are 10 Python list-based questions based on programming concepts:

Programming Questions

1. Write a Python program to create a list numbers containing the numbers 1, 2, 3, 4, and 5. Then,
print the sum of all the numbers in the list. (2 marks)

Answer:

Python

numbers = [1, 2, 3, 4, 5]

total = sum(numbers)

print("Sum of numbers:", total)

2. Write a Python program to create a list fruits containing the names of five fruits. Then, print the
name of the fruit at index 2. (2 marks)

Answer:

Python

fruits = ["apple", "banana", "cherry", "date", "elderberry"]

print("Fruit at index 2:", fruits[2])

3. Write a Python program to create a list numbers containing the numbers 1, 2, 3, 4, and 5. Then,
use a for loop to print each number in the list. (2 marks)

Answer:

Python

numbers = [1, 2, 3, 4, 5]

for num in numbers:

print(num)

4. Write a Python program to create a list words containing five words. Then, use the sort()
method to sort the words in alphabetical order and print the sorted list. (2 marks)

Answer:

Python

words = ["hello", "world", "python", "programming", "language"]


words.sort()

print("Sorted words:", words)

5. Write a Python program to create a list numbers containing the numbers 1, 2, 3, 4, and 5. Then,
use the reverse() method to reverse the order of the numbers in the list and print the reversed
list. (2 marks)

Answer:

Python

numbers = [1, 2, 3, 4, 5]

numbers.reverse()

print("Reversed numbers:", numbers)

6. Write a Python program to create a list fruits containing the names of five fruits. Then, use the
index() method to find the index of the fruit "banana" in the list and print the index. (2 marks)

Answer:

Python

fruits = ["apple", "banana", "cherry", "date", "elderberry"]

index = fruits.index("banana")

print("Index of banana:", index)

7. Write a Python program to create a list numbers containing the numbers 1, 2, 3, 4, and 5. Then,
use the count() method to count the number of occurrences of the number 3 in the list and print
the count. (2 marks)

Answer:

Python

numbers = [1, 2, 3, 4, 5]

count = numbers.count(3)

print("Count of 3:", count)

8. Write a Python program to create a list words containing five words. Then, use the join()
method to concatenate the words in the list into a single string and print the concatenated
string. (2 marks)
Answer:

Python

words = ["hello", "world", "python", "programming", "language"]

concatenated_string = " ".join(words)

print("Concatenated string:", concatenated_string)

9. Write a Python program to create a list numbers containing the numbers 1, 2, 3, 4, and 5. Then,
use a for loop to print the square of each number in the list. (2 marks)

Answer:

Python

numbers = [1, 2, 3, 4, 5]

for num in numbers:

print("Square of", num, ":", num ** 2)

10. Write a Python program to create a list fruits containing the names of five fruits. Then, use the
sort() method to sort the fruits in alphabetical order and print the sorted list. Finally, use the
reverse() method to reverse the order of the fruits in the list and print the reversed list. (2
marks)

Answer:

Python

fruits = ["hello", "world", "python", "programming", "language"]

fruits.sort()

print("Sorted fruits:", fruits)

fruits.reverse()

print("Reversed fruits:", fruits)

You might also like