Assignment 3.5 - kleinay/arieloop2026 GitHub Wiki

Assignment 3.5 - Python Programming

This assignment includes 4 tasks.


1. String Processing & List Comprehension

Write a function that analyzes a given string:

Create a function:

def process_text(s):

The function receives a string s and returns a dictionary with the following keys:

  1. "length" -- the length of the string.
  2. "vowels" -- the number of English vowels (a, e, i, o, u).
  3. "uppercase_letters" -- a list of all uppercase letters in the string (use a list comprehension).
  4. "words_lengths" -- a list containing the lengths of all words in the string (also using a list comprehension).
  • If the string is empty, raise a ValueError.
  • Write code that:
    • reads a string from the user,
    • calls process_text,
    • and prints the resulting dictionary.

2. Functions with Default Parameters

Write a function:

def repeat_frame(text, times=3, left='[', right=']'):

The function returns a string where text appears times times. Each appearance is wrapped with left and right, and the wrapped parts are separated by commas.

Example:

repeat_frame("hi", times=2, left="<<", right=">>")

returns:

"<<hi>>, <<hi>>"
  • Show 3 example calls:
    1. Using only default values
    2. Changing times
    3. Changing only the framing characters
  • Ensure the function works correctly when only some parameters are supplied.

3. Recursion

Write a recursive function:

def digit_sum(n):

that computes the sum of digits of a positive integer n.

  • If n is negative, raise a ValueError.
  • Write another recursive function:
def count_digit(n, d):

that returns how many times the digit d appears in n.


4. Exceptions, Input & Lists

Write a program that asks the user to enter a list of integers (separated by spaces), and then processes the list.

  1. Read user input using input().
  2. Convert the input into a list of integers. If any value is invalid, print an error and ask again.
  3. Use a list comprehension to create a list containing only the negative numbers.
  4. Write a function that returns the maximum value in the list (without using max()).
  5. Print:
    • the original list
    • the list of negative numbers
    • the largest number in the list

Submission Requirements

Submit a single .py file containing:

  • All tasks fully implemented
  • Short explanations (as Python comments) next to your code

Write clean, simple, Python code.

⚠️ **GitHub.com Fallback** ⚠️