Safi ML Lab2
Safi ML Lab2
STEP 4: Using while loop calculates remainder single_digit repeatedly by modulus num with 10.
STEP 5: Calculate the single digit with the power with respect to its position . add this value in the sum.
STEP 7: Check whether the sum is equal to the number(copy of number). If yes, then given number
Theory
1. Python Variables
Variable is a name which is used to refer memory location. Variable also known as identifier and used to
hold value.
In Python, we don't need to specify the type of variable because Python is a type infer language and
smart enough to get variable type. Variable names can be a group of both letters and digits, but they
have
It is recommended to use lowercase letters for variable name. Rahul and rahul both are two different
variables.
LAB TASKS
5. loop through a tuple of mixed data type and extract only integer values
6. Find the following values:
my_dict = {"apple": 2.50, "orange": 4.99, "banana": 0.59, "watermelon": 10.29,
"tomato": 9.02}
Access all the keys in a dictionary
Access all the values in a dictionary
Access both the keys and the values together from a dictionary
Find an average of all values in a dictionary
Conditional looping: filtering dictionary items based on certain conditions
["apple", "orange", "pear", "watermelon"]
Updating values: reduce all values by 25% (in a practical application it
would be like giving a 25% discount on all fruits)
Conclusion
In this lab session, I delved into various foundational Python concepts, ranging from conditional
statements and loops to intricate dictionary operations. The exercises began with determining
prime and Disarium numbers, emphasizing the importance of loops, conditional checks, and
digit manipulation. As I progressed, tasks like calculating the average of ten user-inputted
values and iterating through mixed data type tuples highlighted the significance of user input
validation and type checking. These initial tasks solidified my grasp on basic Python operations
and set the stage for more complex challenges.
The dictionary-based tasks were particularly enlightening. Working with a sample dictionary of
fruit prices, I practiced essential operations like accessing keys and values, and more advanced
techniques like conditional filtering and value updates using dictionary comprehensions. These
exercises simulated real-world data manipulation scenarios, reinforcing the practical
applications of Python in data analysis. By the end of the session, I felt more equipped and
confident in handling and analyzing data, paving the way for future endeavors in machine
learning and AI.