The Task
Write a program based on the following requirements:
- The list must contain several tuples - each tuple should include:
- one name
- one set consisting of numbers
Select only the tuples where the name contains the letter "a" (uppercase or lowercase).
From the sets inside the selected tuples, extract only the even numbers.
Combine all extracted even numbers into a unique collection (no duplicates).
Multiply the resulting unique numbers twice, but:
- do this using a list, not a set.
Sort the final values.
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)
datawhich has names in it. If we only look at steps 1 - 7, you should not be displaying names but rathe just the numbers sorted and converted to a tuple. You are not doing that.