Assignment 3.5 - kleinay/arieloop2026 GitHub Wiki
This assignment includes 4 tasks.
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:
-
"length"-- the length of the string. -
"vowels"-- the number of English vowels (a, e, i, o, u). -
"uppercase_letters"-- a list of all uppercase letters in the string (use a list comprehension). -
"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.
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:
- Using only default values
- Changing
times - Changing only the framing characters
- Ensure the function works correctly when only some parameters are supplied.
Write a recursive function:
def digit_sum(n):that computes the sum of digits of a positive integer n.
- If
nis negative, raise aValueError. - Write another recursive function:
def count_digit(n, d):that returns how many times the digit d appears in n.
Write a program that asks the user to enter a list of integers (separated by spaces), and then processes the list.
- Read user input using
input(). - Convert the input into a list of integers. If any value is invalid, print an error and ask again.
- Use a list comprehension to create a list containing only the negative numbers.
- Write a function that returns the maximum value in the list (without
using
max()). - Print:
- the original list
- the list of negative numbers
- the largest number in the list
Submit a single .py file containing:
- All tasks fully implemented
- Short explanations (as Python comments) next to your code
Write clean, simple, Python code.