Lab 2
Lab 2
EXPERIMENT NO 2
Lab Title: Python: Syntax, Libraries and Uninformed vs. Informed search
Student Name: Ibrahim, Huzaifa, Hassaan Reg. No: 220391, 222590, 222563
Objective:
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Date: Signature:
ABSTRACT
In this lab we will be studying types of searches
Muhammad Ibrahim
220391
BCE 5-A
INTRODUCTION TO AI
Lab 2
Page 1 of 7
LAB 2
Code:
# Task 1
Output:
Code:
# Task 2
Output:
Code:
def calculate_letter_grade(average):
if average >= 90:
return 'A'
elif average >= 80:
return 'B'
elif average >= 70:
return 'C'
elif average >= 60:
return 'D'
else:
return 'F'
# Main program
def main():
# Asking for the number of students (with validation for at least 3)
num_students = int(input("Enter the number of students (minimum 3): "))
while num_students < 3:
print("Please enter at least 3 students.")
# Predefined subjects
subjects = ["Math", "Science", "English"]
Output:
Code:
else:
while stack: # Continue as long as there are nodes to explore
temp = stack.pop() # Pop from the stack (LIFO)
if target == temp:
return visited
else:
for sibling in graphs[temp]: # Explore each adjacent node
if sibling not in visited: # If not visited, add to
visited and stack
stack.append(sibling)
visited.append(sibling)
return shortest
Output:
Conclusions:
In this lab, we explored fundamental Python programming concepts such as user input,
conditional statements, loops, and functions. These tasks provided hands-on experience in
writing Python code, handling conditions, and utilizing loops efficiently. Through these
exercises, we gained a deeper understanding of Python's control structures and built essential
problem-solving skills.