CompSci
  • Home
  •  Unit 1
    Output Exercises
     Unit 2
    Variables Math Modules Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    Iteration / Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Lists Exercises
     Unit 7
    Functions Exercises
  •  Unit 1
    Java Introduction Java Syntax Errors & Coding Conventions Format Method Exercises
     Unit 2
    Variable Introduction Math / Arithmetic Operators Obtaining a Value Formatting Numeric Output Concatenation & Constants Division & Type Casting Exercises
     Unit 3
    Conditionals Exercises
     Unit 4
    while Loops for Loops Exercises
     Unit 5
    Strings Exercises
     Unit 6
    Methods Method Parameters Method Return Types Exercises
  • Muddy City
  • Github Classroom
  •  Assignments
    Add an Assignment Edit Assignment Search Program Code
     Forum
    Ask a Question Search the Forum
     New Account
    New Account


Account Mgmt
Reset Password

Python - Lists


Exercises

Find the Average

Difficulty: Low

Title: Find the Average

Description:
Create a program that takes user input of five numbers and determine the average.

  • Organize the numbers from smallest to largest.
  • Ignore the smallest and largest number when determining the average.
  • Output the list created.
  • Output the average (truncate / round down) to the nearest whole number.

Output:
Number: 20
Number: 15
Number: 1
Number: 5
Number: 10

List: 1, 5, 10, 15, 20
Average: 10


Find Words Longer Than

Difficulty: Low

Title: Find Words Longer Than

Description:
Write a Python program to find the list of words that are longer than a given length from a given list of words.

  • Prompt the user for a list of five words.
  • Prompt the user for a given length to find.
  • Output the original list.
  • Output the words that are equal to or greater than a given length.
  • If no words are greater than or equal to the length inputted, output: "No matches found"

NOTE: The output of the list (see example output) is not simply outputting the list itself. Think Strings and concatenation.

Output:
Word: charity
Word: utter
Word: snow
Word: bench
Word: at
Word Length: 5

List: charity, utter, snow, bench, at
Words Matching: charity, utter, bench


Same Characters

Difficulty: Medium

Title: Same Characters

Description:
Create a program that takes five user inputs and puts them into a list to count the number of strings that match the following criteria:

  • The string length has to be 3 or more to be considered in the count.
  • The first and last characters are the same to be considered in the count.
  • Output the list created.
  • Output the final count.

NOTE: The output of the list (see example output) is not simply outputting the list itself. Think Strings and concatenation.

Output:
Word: aba
Word: cat
Word: that
Word: dog
Word: pop

List: aba, cat, that, dog, pop
Count: 3


Comparing Lists

Difficulty: High

Title: Comparing Lists

Description:
Create a program that prompts the user for two lists of five words each and compare the lists for similarities and differences between the two lists.

  • Output the two lists.
  • Output the similarities.
  • Output the differences in the order they were entered.

NOTE: The output this time of the list is just printing the list.

Output:
Word: cat
Word: dog
Word: fish
Word: bat
Word: cow

Word: dog
Word: eel
Word: bat
Word: ant
Word: lama

List One: ['cat', 'dog', 'fish', 'bat', 'cow']
List Two: ['dog', 'eel', 'bat', 'ant', 'lama']
Similarities: dog bat
Differences: cat fish cow eel ant lama


One Letter Change Up

Difficulty: High

Title: One Letter Change Up

Description:
Write a program to prompt the user for a short word, three to five letters. Read from a dictionary (see Python - Sample Code and see how many words you can find by changing one letter at a time).

  • Output the words as you find them, but DO NOT include the word to be found.
  • Output the total words found.
  • Ignore case sensitivity (i.e. "H" and "h" should be treated as the same character).

Reading From a File
# creating variable to store the
# number of words
number_of_words = 0

# Opening our text file in read only
# mode using the open() function
with open(r'SampleFile.txt','r') as file:

  # Reading the content of the file
  # using the read() function and storing
  # them in a new variable
  data = file.read()

  # Splitting the data into separate lines
  # using the split() function
  lines = data.split()

# Printing total number of words
print(lines)

Output:
Input a string: boat

boat
coat
doat
goat
moat
toat
beat
bhat
...



Computer Science