+91 81900 98289

Python Practice Problems

This Python Practice Problems lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

Three short problems: count the names that contain the letter a, average a list of scores, and return the cities that appear more than once.

Solve them in the try-it editor. The example answers the first one.

Example 1: Start here

Meera, Arun, and Divya each contain an a, so the count is 3.

names = ["Meera", "Arun", "Divya"] # a list; the values stay in this order print(sum(1 for name in names if "a" in name.lower())) # keep the items that pass the test

Example 2: Sum a list

sum adds every number in the list.

print(sum([10, 20, 30])) # add the numbers together

Example 3: Unique skills

A set drops the repeated Python. sorted gives a stable order for printing.

print(sorted({"Python", "SQL", "Python"})) # a new list, sorted

Example 4: Word count

split breaks the sentence on spaces. len counts the words.

text = "learn python today" # text print(len(text.split())) # len counts the items
Meera, Arun, and Divya each contain an a, so the count is 3.
Call Now 81900 98289