0% found this document useful (0 votes)
65 views6 pages

Lab Manual For Bca Second Year

Uploaded by

bliickg00n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

Lab Manual For Bca Second Year

Uploaded by

bliickg00n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB MANUAL FOR BCA SECOND YEAR

PYTHON PROGRAMMING

AIM1. What is Python? What are applications of Python? Explain with example.
ANS. Python is one of the easiest yet most useful programming languages which is widely
used in the software industry. People use Python for Competitive Programming, Web
Development, and creating software. Due to its easiest syntax, it is recommended for
beginners who are new to the software engineering field. Its demand is growing at a very
rapid pace due to its vast use cases in Modern Technological fields like Data Science,
Machine learning, and Automation Tasks.
Applications of Python
1. Web Development
Developers prefer Python for web Development, due to its easy and feature-rich framework.
They can create Dynamic websites with the best user experience using Python frameworks.
Some of the frameworks are -Django, for Backend development and Flask, for Frontend
development.
2. Data Science
Data scientists can build powerful AI models using Python snippets. Due to its easily
understandable feature, it allows developers to write complex algorithms. Data Science is
used to create models and neural networks which can learn like human brains but are much
faster than a single brain.
3. Web Scrapping and Automation
You can also automate your tasks using Python with libraries like Beautiful soup, Panda,
Matplotlib etc. for scraping and web automation.
4. CAD
You can also use Python to work on CAD (computer-aided designs) designs, to create 2D and
3D models digitally. There is dedicated CAD software available in the market, but you can
also develop CAD applications using Python also.
5. Artificial Intelligence and Machine Learning
Using libraries like Pandas, and TensorFlow, experts can work on data analysis and machine
learning applications for statistical analysis, data manipulation, etc. Python is one of the most
used Programming languages in this field. It is worth saying that Python is the language of AI
and ML.
6. Game Development
Python can also be used by developers to build games using Pygame to develop 2D and 3D
games. Some of the popular games built using Python are Pirates of the Caribbean,
Battlefield 2, etc.
AIM 2. Write a Python code to print “Hello Python”.
ANS. Python Code to print Hello Python is;
Print(“Hello Python”)
Output:
Hello Python
AIM 3. What is Variable in Python? How Variable is defined? Explain with Code.
ANS. Variables are containers for storing data values. A variable is created the moment you
first assign a value to it.
For Example.
x= 5
y= "John"
print(x)
print(y)
Output:
5
John
Note: Variables do not need to be declared with any particular type, and can even change type
after they have been set.
For example.
x=4 # x is of type int
x = "Sally" # x is now of type str
print(x)
Output:
Sally
AIM 4. What are Data types in Python? Write a python Code for INT, FLOAT and
COMPLEX type.
Ans. In programming, data type is an important concept. Variables can store data of different
types, and different types can do different things. Python has the following data types built-in
by default, in these categories:

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range


Mapping Type: dict

Set Types: set, frozenset

Boolean Type: Bool

Binary Types: bytes, bytearray, memoryview

None Type: NoneType

Python Numbers
There are three numeric types in Python:
 int
 float
 complex
Variables of numeric types are created when you assign a value to them:
For Example:
x= 1 #int
y= 2.8 #float
z = 1j # complex
To verify the type of any object in Python, use the type() function:
x=1
y = 2.8
z = 1j
print(type(x))
print(type(y))
print(type(z))
Output:
<class'int'>
<class'float'>
<class 'complex'>
AIM 5: Explain the following Built-in Function.
A) List
b) Tuple
c) Dictionary
Ans. A) List:
A list is a data structure in Python that is a mutable, or changeable, ordered sequence of
elements. Each element or value that is inside of a list is called an item. Just as strings are
defined as characters between quotes, lists are defined by having values between square
brackets [ ] .
B) Tuple
Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data
types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all
with different qualities and usage. A tuple is a collection which is ordered and unchangeable.
C) Dictionary
A Python dictionary is a data structure that stores the value in key: value pairs. Values in a
dictionary can be of any data type and can be duplicated, whereas keys can’t be repeated and
must be immutable. Python dictionaries are essential for efficient data mapping and
manipulation in programming.
AIM 6: Write a Python code to create a List with example.
Ans: Lists are used to store multiple items in a single variable. Lists are created using square
brackets:
Example
Create a List:
thislist=["apple", "banana", "cherry"]
print(thislist)
Output:
['apple', 'banana', 'cherry']
AIM 7: Write a Python code to create a Tuple with example.
Ans: Tuples are used to store multiple items in a single variable. A tuple is a collection which
is ordered and unchangeable. Tuples are written with round brackets.
Example
Create a Tuple:
thistuple=("apple", "banana", "cherry")
print(thistuple)
Output:
('apple', 'banana', 'cherry')
AIM 8: Write a Python code to create a Dictionary with example.
Ans. Dictionaries are used to store data values in key:value pairs. A dictionary is a collection
which is ordered*, changeable and do not allow duplicates. As of Python version 3.7,
dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered. Dictionaries
are written with curly brackets, and have keys and values:
Example
Create and print a dictionary:
thisdict= {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Output:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
AIM 9: How Database is utilised using Python? Create a database ‘MyDatabase’.
Ans. Python can be used in database applications. One of the most popular databases is
MySQL. Python needs a MySQL driver to access the MySQL database.
Creating a Database
To create a database in MySQL, use the "CREATE DATABASE" statement:
Example
create a database named "mydatabase":
import mysql.connector

mydb=mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword"
)

mycursor=mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")


Output:
Mydatabase is created
AIM 10: Write a python code to create a table Student with STD_ID, STD_Name and
STD_CTNO.
Ans. To create a table in MySQL, use the "CREATE TABLE" statement. Make sure you
define the name of the database when you create the connection.
Example
Create a table named "Student":
import mysql.connector

mydb=mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="mydatabase"
)

mycursor=mydb.cursor()

mycursor.execute("CREATE TABLE Student (STD_ID INTEGER, STD_Name


VARCHAR(255), STD_CTNO INTEGER)")
Output:
Student Table Created
STD_ID STD_Name STD_CTNO

You might also like