Page 287 - Ai_C10_Flipbook
P. 287
[2]: i = 1
while i < 6:
print(i)
i += 1
1
2
3
4
5
[3]: #input a number and check for even or odd.
#The whole process should continue till the user wants.
ans = 'y'
while ans == 'y':
Num = int(input("Enter a number: "))
if Num%2 == 0:
print (Num," is an even number")
else:
print (Num," is an odd number")
ans = input("Enter y to continue: ")
print ("Program ends here")
Enter a number: 20
20 is an even number
Enter y to continue: y
Enter a number: 21
21 is an odd number
Enter y to continue: n
Program ends here
Reboot
• What are conditional statements?
• What are the different kinds of loop?
Modules and Packages
A module is a Python file (.py) that contains Python code, including functions, classes, and variables, which can
be reused in other programs. Modules help in structuring code efficiently by breaking it into manageable parts.
A package is a collection of related Python modules organized within a directory. It typically includes an __init__.
py file, which indicates that the directory should be treated as a package. Python provides numerous built-in and
third-party packages to simplify coding tasks.
Below are some commonly used Python packages:
• NumPy: NumPy (Numerical Python) is a library for numerical computing. It provides support for multidimensional
arrays and matrices, along with a collection of mathematical functions for efficient operations. It is widely used
in data analysis, scientific computing, and Machine Learning due to its high performance and ease of use.
• Pandas: Pandas is a Python library for data manipulation and analysis. It offers powerful data structures like
Series and DataFrames for handling structured data. It simplifies tasks like data cleaning, transformation, and
aggregation, making it essential for data science workflows.
Advance Python (Practical) 285

