Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2024), B.Sc. in CSE (Day)

Lab Report NO 01

Course Title: Artificial Intelligence Lab


Course Code: CSE 316 Section: 212-D5

Lab Experiment Name: Introduction to basic operations on Python.


Student Details

Name ID

1. Tahsin Ahmmed 212002063

Submission Date : 12-03 -2024


Course Teacher’s Name : Sheikh Fazle Rabbi

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
1. TITLE OF THE LAB REPORT EXPERIMENT
Introduction to basic operations on Python.
2. OBJECTIVES/AIM :
1.Understanding Variable Assignments:
• Learn how to assign values to variables in Python.
• Explore different data types, including integers, floating-point numbers, and strings.
• Recognize the importance of variables as containers for storing and manipulating data.
2.Exploring Arithmetic Operations:
• Gain proficiency in performing basic arithmetic operations in Python.
• Practice using variables and constants in mathematical expressions.
• Understand how Python handles numerical calculations and the rules for operator
precedence.
3.Mastering String Manipulation:
• Familiarize yourself with essential string operations in Python.
• Learn to concatenate strings, extract substrings, and use string formatting.
• Understand the significance of strings as a fundamental data type.
4.Introducing Control Structures:
• Grasp the concept of control structures in Python.
• Explore conditional statements (if, elif, else) to make decisions based on conditions.
• Understand loops (for, while) for iterating over sequences and controlling program
flow.
5.Building a Foundation for Programming Logic:
• Develop a foundational understanding of programming logic and flow control.
• Recognize the role of variables, arithmetic operations, strings, and control structures in
building logical programs.
• Gain confidence in using basic Python operations as building blocks for more complex
programming tasks.
6.Enhancing Problem-Solving Skills:
• Apply Python's basic operations to solve simple programming problems.
• Enhance problem-solving skills by translating real-world scenarios into Python code.
• Develop the ability to break down problems into manageable components and use
Python to implement solutions.
7.Promoting Hands-On Learning:
• Emphasize hands-on learning through practical exercises and examples.
• Encourage active participation in coding activities to reinforce theoretical concepts.
• Foster a learning environment that allows students to experiment and explore Python's
capabilities.
3. PROCEDURE / ANALYSIS / DESIGN

For task 1: Write a Python Program to Count Even and Odd Numbers in a list.
1. Define a function count_even_odd that takes a list of numbers as input.
2. Initialize counters for even and odd numbers.
3. Use a for loop to iterate through each number in the provided list.
4. Check if the number is even or odd using the modulus operator (%).
5. Increment the corresponding counters based on whether the current number is even or odd.
6. Prompt the user to input a list of numbers separated by spaces.
7. Convert the user input, which is a string, into a list of integers.
8. Use a list comprehension to achieve this.
9. Call the count_even_odd function with the user-provided list of numbers.
10. Print the count of even and odd numbers obtained from the function.
11. For example, if the user inputs "2 4 5 7 8," the program will output the count of even
numbers (3) and odd numbers (2).
For task 2: Write a Python program to get the 4th element from the beginning and the 4th element
from the last of a tuple.
1. Define a function get_elements that takes a tuple (tuplex) as input.
2. Check if the length of the tuple is greater than or equal to 4.
3. If the tuple has enough elements, retrieve the 4th element from the beginning
(fourth_from_beginning) using index 3.
4. Retrieve the 4th element from the end (fourth_from_end) using negative index -4.
5. If the tuple has enough elements, return a tuple containing both the 4th element from the
beginning and the 4th element from the end.
6. If the tuple does not have enough elements, return a message indicating that.
7. Initialize a sample tuple (tuplex) with elements ("w", 3, "r", "e", "s", "o", "u", "r", "c", "e").
8. Call the get_elements function with the sample tuple.
9. Print the result obtained from the function, which includes the 4th element from the
beginning and the 4th element from the end.
4. IMPLEMENTATION
Task 1:
def count_even_odd(numbers):
even_count = 0
odd_count = 0

for number in numbers:


if number % 2 == 0:
even_count += 1
else:
odd_count += 1

return even_count, odd_count

# Take input from the user


user_input = input("Enter a list of numbers separated by spaces: ")
numbers_list = [int(num) for num in user_input.split()]

# Call the function with user-provided list


even_count, odd_count = count_even_odd(numbers_list)

# Display the results


print("Even numbers:", even_count)
print("Odd numbers:", odd_count)

Task 02:
def get_elements(tuplex):
if len(tuplex) >= 4:
# Get the 4th element from the beginning
fourth_from_beginning = tuplex[3]

# Get the 4th element from the end


fourth_from_end = tuplex[-4]

return fourth_from_beginning, fourth_from_end


else:
return "Tuple does not have enough elements"

# Sample Input
tuplex = ("w", 3, "r", "e", "s", "o", "u", "r", "c", "e")

# Get and print the result


result = get_elements(tuplex)
print("4th Element from the beginning and last are : ")
print(result)

5. TEST RESULT / OUTPUT

Task 01:

Task 02:
6. ANALYSIS AND DISCUSSION:

The lab report gives a quick rundown of what we learned in the "Introduction to Basic Operations
in Python." It covers the basics like assigning values to variables, doing math operations,
manipulating text, and using control structures for decision-making. The report stresses the
importance of hands-on learning through practical exercises and shows how these fundamental
skills are crucial for problem-solving. It also hints at how this basic knowledge sets the stage for
exploring more advanced topics in Python, making it a solid starting point for anyone diving into
programming with Python.

You might also like