You are on page 1of 9

Lovely Professional University

Course Code: MGNM801 Course Title:Business Analytics-1


Course Instructor: Dr. Mohd Imran khan Academic Task No.: 2

Date of submission: 26-12- 2022


Student Name: Varun saini Section: Q2242
Student’s Roll No: B44 Student’s Reg. No: 12204289
Declaration:
I declare that this Assignment is my individual work. I have not copied it from any other student’s work or from
any other source except where due acknowledgement is made explicitly in the text, nor has any part been written
for me by any other person.

Student’s Signature:

Evaluator’s comments (For Instructor’s use only)

General Observations Suggestions for Improvement Best part of assignment Marks

Obtained: Max. Marks:

Evaluator’s Signature and Date:


Q1: What is python? Explain the following concepts with examples:
o Variables
o Keywords
o Identifiers
o Operators
Answer:

Python is a high-level, interpreted programming language. It was first released in


1991 by Guido van Rossum, and has since become one of the most popular
programming languages in the world.
Python is known for its simplicity, readability, and flexibility. It is a general-purpose
language, which means that it can be used to build almost any type of software, from
desktop applications to web servers and scientific applications.

One of the main advantages of Python is its large standard library, which provides
many useful modules and functions for common programming tasks, such as
connecting to web servers, reading and writing files, and working with data.

Python is also widely used in scientific computing, data analysis, and machine
learning, thanks to its powerful numerical and scientific libraries, such as NumPy,
SciPy, and scikit-learn.

 Variables:
o In programming, a variable is a storage location for a value. You can
think of a variable as a box that has a name and holds a value. In Python,
you can create a variable by assigning a value to it using the assignment
operator (=). For example:


 Keywords:
o In Python, keywords are special words that have a specific meaning and
cannot be used as variables or function names. There are 35 keywords in
Python . Here are a few examples:
 Identifiers:
An identifier is a name used to identify a variable, function, class,
module, or other object in Python. Identifiers can contain letters, digits,
and underscores, but they must start with a letter or an underscore. Here
are a few examples of valid identifiers:
WORNG METHOD :

CORRECT METHOD:

 Operators:
o In Python, an operator is a special symbol that performs an operation on
one or more operands (values). For example, the + operator is used to add
two values, the * operator is used to multiply two values, and the =
operator is used to assign a value to a variable. Here are a few examples
of operators in Python:

I USE SOME EXAMPLES OF OPERATORS:


Q2: Show 1 to 10 counting with the help of for and while loop.
Answer:

 for loop to count from 1 to 10 in Python:

 while loop to count from 1 to 10 in Python:

The while loop continues to execute as long as the condition (i <= 10) is True.
The variable i is incremented by 1 at the end of each iteration using the +=
operator.
Q3: Write a program to describing the major methods we can apply on the
following datatypes:
 Lists
 Strings
 Tuples
 Dictionaries
Also describe each datatype in brief
Answer:
 Lists:
o A list is an ordered collection of values that can be of any data type. Lists
are defined using square brackets [ ] and can contain elements of different
data types. Here are some common methods that can be applied to lists:
 append(): Adds an element to the end of the list.
 extend(): Adds all the elements of an iterable (such as a list or a
string) to the end of the list.
 insert(): Inserts an element at a specific position in the list.
 remove(): Removes an element from the list.
 index(): Returns the index of the first occurrence of an element in
the list.
 count(): Returns the number of occurrences of an element in the
list.
 sort(): Sorts the elements of the list in ascending order.
 reverse(): Reverses the order of the elements in the list.
 Example:


 Strings:
o A string is a sequence of characters that can be of any data type. Strings
are defined using single or double quotes. Here are some common
methods that can be applied to strings:
 capitalize(): Capitalizes the first letter of the string.
 upper(): Converts all the characters in the string to uppercase.
 lower(): Converts all the characters in the string to lowercase.
 swapcase(): Swaps the case of all the characters in the string.
 title(): Capitalizes the first letter of each word in the string.
 split(): Splits the string into a list of substrings based on a specified
separator.
 join(): Concatenates a list of strings into a single string using a
specified separator.
 find(): Returns the index of the first occurrence of a specified
substring in the string.
 replace(): Replaces all occurrences of a specified substring with
another substring.
 Example:


 Tuples:
o A tuple is an immutable (unchangeable) sequence of values that can be of
any data type. Tuples are defined using parentheses ( ) and can contain
elements of different data types. Here are some common methods that can
be applied to tuples:
 count(): Returns the number of occurrences of an element in the
tuple.
 index(): Returns the index of the first occurrence of an element in
the tuple.
 Example:
 Dictionaries:
o A dictionary is an unordered collection of key-value pairs. Each key is
associated with a value, and you can use the key to access the value.
Dictionaries are defined using curly braces { } and are separated into key-
value pairs using a colon (:). Here are some common methods that can be
applied to dictionaries:
 get(): Returns the value of a specified key.
 update(): Updates the dictionary with the key-value pairs of
another dictionary.
 pop(): Removes a specified key and its value from the dictionary.
 keys(): Returns a view of the keys in the dictionary.
 values(): Returns a view of the values in the dictionary.
 items(): Returns a view of the key-value pairs in the dictionary.
 clear(): Removes all the key-value pairs from the dictionary.
 Example:

You might also like