I want to show on screen all the users that live in Madrid in the following format:
The user 'NAME', lives in 'CITY' has an age of 'AGE' years old and its debt is: 'DEBT' EUR.
As you can see the different ways in which Madrid is saved, I want to find a way to print these users, since a few write in capital letters and others do not, they all live in Madrid.
students = [
('Marcos', 23, 'Madrid', 850, '2388711341'),
('Elena', 35, 'MaDrid', 360, '0387700342'),
('Carmen', 21, 'Getafe', 50, '0014871388'),
('Carlos', 41, 'MAdrid', 580, '00887118456'),
('Maria', 28, 'Madrixx', 150, '587')
]
for item in students: student, age, town, debt, id = item
The desired result:
The user Marcos lives in Madrid, has an age of 23 years old and its debt is: 850 EUR.
The user Elena lives in Madrid, has an age of 35 years and its debt is: 360 EUR.
The user Carlos lives in Madrid, has an age of 41 years old and its debt is: 580 EUR.
The user Maria lives in Madrid, has an age of 28 years old and its debt is: 150 EUR.
It's really hard to identify what you want, but if you are trying to print alumni data living in Madrid, try below.
students = [
('Marcos', 23, 'Madrid', 850, '2388711341'),
('Elena', 35, 'MaDrid', 360, '0387700342'),
('Carmen', 21, 'Getafe', 50, '0014871388'),
('Carlos', 41, 'MAdrid', 580, '00887118456'),
('Maria', 28, 'Madrixx', 150, '587')
]
for student_detail in students:
if student_detail[2].lower().startswith('madri'):
print(f"The user {student_detail[0]}, lives in Madrid. S/He is {student_detail[1]} years old and has {student_detail[3]} as debt")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With