0% found this document useful (0 votes)
3 views

Lab 4 ipynb - Colab

Uploaded by

hbashir659
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab 4 ipynb - Colab

Uploaded by

hbashir659
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

def filter_adult_students(students):

return tuple(name for name, age in students if age >= 18)

students = (("Saif", 17), ("AL", 18), ("Quida", 20), ("Azam", 16))


adult_students = filter_adult_students(students)
print(adult_students)

('AL', 'Quida')

def sum_of_tuples(tuples_list):
return [sum(tup) for tup in tuples_list]

tuples_list = [(1, 9), (5, 4), (7, 6)]


sums = sum_of_tuples(tuples_list)
print(sums)

[10, 9, 13]

def get_initials(names):
return tuple(f"{name[0]}{name.split()[1][0]}" for name in names)

names = ("Saif Muddasr", "Hamza Bashir", "Amin Arqam")


initials = get_initials(names)
print(initials)

('SM', 'HB', 'AA')

CODE 4

def max_in_tuple(numbers):
if not numbers:
return None
return max(numbers)

numbers = (3, 1, 44, 1, 5, 9)


max_value = max_in_tuple(numbers)
print(max_value)

empty_tuple = ()
max_value_empty = max_in_tuple(empty_tuple)
print(max_value_empty)

44
None

def count_vowels_in_names(names):
vowels = "aeiouAEIOU"
count = 0

for name in names:


count += sum(1 for char in name if char in vowels)
return count
names = ("Saif", "Ali", "Ahmed", "Sial")
vowel_count = count_vowels_in_names(names)
print(vowel_count)

def check_enrollment(student_dict, student_name):


return student_dict.get(student_name, "Student not found")

enrollment_status = {
"Saif": True,
"Sial": False,
"Amin": False,
"Arqam": False
}

student_name_to_check = "Saif"
status = check_enrollment(enrollment_status, student_name_to_check)
print(f"{student_name_to_check}: {status}")
student_name_not_found = "Amin"
status_not_found = check_enrollment(enrollment_status, student_name_not_found)
print(f"{student_name_not_found}: {status_not_found}")

Saif: True
Amin: False

def user_portal():
users = {}

while True:
response = input("Are you a registered user? (yes/no): ").lower()

if response == 'no':
# Sign up process
username = input("Enter your username: ")
password = input("Enter your password: ")
users[username] = password
print("Registered successfully.")

elif response == 'yes':


# Log in process
username = input("Enter your username: ")
password = input("Enter your password: ")

if username not in users:


print("User is not registered.")
elif users[username] != password:
print("Wrong password.")
else:
print("Login successful.")
break

else:
print("Please answer 'yes' or 'no'.")

user_portal()

Are you a registered user? (yes/no): yes


Enter your username: hamza
Enter your password: 1234
User is not registered.

You might also like