FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
1.3k views
in WBUT B.Tech (CSE-III Sem) IT Workshop (Sci Lab/MATLAB/Python/R) Lab by Goeduhub's Expert (3.1k points)
Modules: Importing module, Math module, Random module, Packages, Composition, Input-Output Printing on screen, Reading data from keyboard, Opening and closing file, Reading and writing files, Functions

1 Answer

0 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
 
Best answer

Modules in Python

A module allows you to logically organize your Python code and  can define functions, classes and variables. A module can also include a runnable code.

Math Module

  1. Python math module is used to perform mathematical operations in python.
  2. The math module is a standard module in Python and is always available.
  3. We can use all functionality of math module by importing it

Let's see it by an example 

# Square root calculation

import math

print(math.sqrt(256))

print(math.sqrt(111))

Output

16.0
10.535653752852738

Note: Math module has number of function/methods, here we used sqrt (for square root)

Python Random Module 

Random module is used to generate random numbers in python.

import random

random.seed(2)

print(random.random())

print(random.random())

Output

0.9560342718892494
0.9478274870593494

Note: Random module also have number of function/methods , here i mentioned some of them 

Function/MethodsDescription
seed()Initialize the random number generator
shuffle()Takes a sequence and returns the sequence in a random order
sample()Returns a given sample of a sequence
random()Returns a random float number between 0 and 1

Input-Output Printing on screen, Reading data from keyboard

#Reading data from keyboard or input 

a= input("Enter your name : ") 

#Printing input data

print("Printing input on screen=", a)

Output

Enter your name : Goeduhub Technologies
Printing input on screen= Goeduhub Technologies

Python Packages

A package is basically a directory with Python files and a file with the name __init__.py.

Example: Pandas, Numpy, Sklearn , Pygame all are python packages and libraries to perform specific task.

Let's see a simple example 

Problem: We have a list and we want to convert it in a Series

Solution: We can do this problem in core python but we have to write a long code, let's see how pandas do this 

#To use pandas first we have to import pandas

import pandas as pd

#Here pd just a object of pandas 

#Defining a List

A=['a','b','c','d','e']

#Converting into a series 

df=pd.Series(A)

print(df)

Output

Note:  As you can see from the output our list is converted into a series with index.

File Handling in Python click here for Article

WBUT B.Tech (CSE-III Sem) IT Workshop (Sci Lab/MATLAB/Python/R) Lab for more question and  answers Click Here


Python Tutorial 

Machine Learning Tutorial 

AI Tutorial

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 210 views
0 like 0 dislike
1 answer 230 views
0 like 0 dislike
1 answer 372 views
0 like 0 dislike
1 answer 160 views
0 like 0 dislike
1 answer 249 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...