[Python] Having trouble with an assignment that involves processing tuples containing a str...

Discussão em 'Python' iniciado por Stack, Novembro 28, 2025.

  1. Stack

    Stack Membro Participativo

    The Task


    Write a program based on the following requirements:

    1. The list must contain several tuples - each tuple should include:
    • one name
    • one set consisting of numbers

    1. Select only the tuples where the name contains the letter "a" (uppercase or lowercase).


    2. From the sets inside the selected tuples, extract only the even numbers.


    3. Combine all extracted even numbers into a unique collection (no duplicates).


    4. Multiply the resulting unique numbers twice, but:
    • do this using a list, not a set.

    1. Sort the final values.


    2. Display the result as a tuple.

    Output: It prints the student's name, age, course, and university as entered by the user.


    Either there is a mistake somewhere in the question or I'm too dumb. This task came with the midterm test I took yesterday. "There is nothing complicated and I made it only for beginner level python learners" - as my teacher said (yeah sure no doubt).

    It could be better if you guys give me hints and point out where am I going wrong instead of giving out the whole thing. I would have just gone to ask chatgpt, but I feel like I'm near solving it so yeah that is why I'm here.

    name = input('ur name: ')
    age = int(input('ur age: '))
    course = int(input('ur course: '))
    univ = input('ur uni: ')

    student = [
    ('adam', {1,2,3}),
    ('john', {4,5,6,7}),
    ('alan', {8,9,10,11})
    ]

    student.append((name, {age, course}))

    data = []
    nums = set()

    for i, z in student:
    if 'a' in i:
    data.append(i)
    for n in z:
    if n % 2 == 0:
    nums.add(n)

    for i in nums:
    i *= 4
    data.append(i)

    print(data)

    Continue reading...

Compartilhe esta Página