You are on page 1of 52

5-July-2023

1. Write a program that takes two numbers as


input and performs all basic arithmetic
operations (addition subtraction, multiplication,
and division) on them.
Method-1

Method-2 input from user.


06-July-2023
1. Print a string using a print statement.
2.Print the given string using indentation (space
between characters)

3.Print the factorial of the number.


10-July-2023
Python Operators
Arithmetic Operators
Arithmetic Operators perform various arithmetic calculations like addition,
subtraction, multiplication, division, %modulus, exponent, etc. There are
various methods for arithmetic calculation in Python like you can use the eval
function, declare variable & calculate, or call functions.
Comparison Operators
These operators compare the values on either side of the operand and
determine the relation between them. It is also referred to as relational
operators. Various comparison operators are (==, != , <>, >,<=, etc).
Assignment Operators
Python assignment operators are used for assigning the value of the right
operand to the left operand. Various assignment operators used in Python are
(+=,-=,*=,/=,etc.)
Bitwise Operators
Bitwise operators are characters that represent actions (bitwise operations) to
be performed on single bits. They operate at the binary level and perform
operations on bit patterns that involve the manipulation of individual bits.

Logical Operators
There are three logical operators in Python - and, or and not. They are used to
combine two or more conditional statements.

Membership Operators
Membership operators in and not in are used to find whether a value is present
in a particular Python object or not.
Identity Operators
Identity operators is and is not are used to check whether the memory
locations of two variables/objects are the same or not. Also, we can use these
operators to find if a variable/object belongs to a particular type or not.

CONDITIONAL STATEMENT
If Statement
This is the simplest decision-making statement in Python. It is used to decide if
a particular block of code needs to be executed or not. Whenever the given
condition is True, then the block of code inside it gets executed, else it does
not.

If else Statement
The statements written within the else block get executed whenever the if
condition is False. You can imagine the flow of execution this way,

Elif Statement
The keyword elif is a combination of else and if. This statement works similar to
'else if' statements in the C and other languages. The statements in elif block
get executed when the previous if condition is False.
Nested If statement
One if statement inside another if statement is called Nested if statement. The
structure and flow of execution can be assumed as shown below.

Single Statement Suites


If the suite of an if clause consists only of a single line, it may go on the same
line as the header statement.
12-July-2023
LOOPS
A loop is an instruction that repeats multiple times as long as some
condition is met.

While loop
The while loop checks the condition first, and if it returns true, the code within
it runs. The loop continues until the condition provided returns false, then
stops.

For loop
for loops are used when you have a block of code which you want to repeat a
fixed number of times. The for-loop is always used in combination with an
iterable object, like a list or a range. The Python for statement iterates over the
members of a sequence in order, executing the block each time.

Nested Loop
Nested for loops places one for loop inside another for loop. The inner loop is
repeated for each iteration of the outer loop.

13-July-2023
1.Perform Control Statement in Python.
2.Write a program in sum of n numbers.

3.Write a program in multiply of n numbers.


14-July-2023
1. Write a program to add numbers and
string to the current list using the append list
method.

2. Write the Python program to get the


largest number from a list using max and min
command.
3. Write a Python program to find whether a
given number (accept from the user) is even
or add by using if-else command.

17-July-2023
1. Write a Python program to create a tuple.
2. Write a Python program to create a tuple with
different data types.

4. Write a Python program to convert


temperatures to and from Centigrade to
Fahrenheit

4. Write a python program multiplying strings to


form string with repeating sequence
5. Write a Python program to create a dictionary
and perform functional operations
19-July-2023
Modules
1. Create and import module
 Create first file like cal.py and enter the code.
 Then create second file output.py and import your functions
and run it.
Output: - Not- This is a user defined modules.

Increment Decrement In modules using IDLE shell

2. Loading and reloading Modules


 Open IDLE shell and run this code.
3. How to check module list.

4. Dir function use

5. How to find all paths.


20-July-2023
Python File handling
 Create a text file using (x)

 Write some content in the file using (w)

 Read file using (r)


 Read only one line in the file.

 Read all line of the file.

 Fined file if exist here it will be open


otherwise print a massage.
 Close file using close().

Copy file’s content in another file. and after copy


and pest the content you can read your new file.
 Delete the file.

24-July-2023
1.write a program to find out what version of
python you are using.
2.write a program to find out the current date
and time.

3.write a python program to calculate the area


of circle based on the radius entered by the
user.

4.write a python program to display the first &


last colors of the list.

25-July-2023
1. Write a python program that print a
calendar of a given month and year.

2. Write a python program to calculate the


number of days between two dates.

3. Write a python program to calculate the sum


of three given numbers if the values are equal
written three times sum.
4. Write a python program to create a
histogram from a given list of integers.

26-July-2023
1.Write a python program to handle a zero
Division error exception when dividing a
number by zero.
2.Write a python program that prompts the
user to input an integer and raises a value
error exception if the input is not a valid
integer.

02-Agust-2023
CURD OPERATION
After CRUD Operation we need to install some software and
driver like Python, MySQL Workbench and a connector driver
(pip).
Step 1: - Go to the search bar and type Python.exe You will
see a Python exe file. place to open file
Step 2: - Double Click on Scripts folder.
Step 3: - click on address bar and type CMD

Step 4: - Open after open CMD write the command.


Command for Pip diver: - pip install mysql-connector-python

 Connection with MySQL.


Output: -

 Check the list of databases

Output: -
If you want to see whether these databases are in mysql or
not, then open mysql and you can see.

 Create a new database


Output: -

New database created

 Create a new table


Output: -

Now we will see in mysql whether the new table is


created or not.
 Add a new column in the table

Output: -

You can see add a new column on the table.

 Insert data in the table


Output: -

After inserting data result in mysql

 Insert multiple value in once.


Output: -

Now you will see After inserting data inserted in mysql


 Read the inserted data

Output: -

 Update data
Output: -

You will the Update on the Mysql

Update to Hathras from


Gwalior

 Delete data
Output: -

Now you will see in the mysql table your data is deleted.

Rahila's data has been deleted from here

03-Agust-2023
Python_Flask
Flask is an API of Python that allows us to build up web-
applications. It was developed by Armin Ronacher. Flask's
framework is more explicit than Django's framework and is
also easier to learn because it has less base code to
implement a simple web-Application.
INSTALLATION OF VIRTUAL ENVIRONMENT
Step 1: -Open VS code Editor and Create a new python_flask
folder in any location.
Step 2: -Open Terminal on Vs code and run the command
for installed virtual environment and hit enter.
Command: - pip install virtualenv

STEP 3: - Then enter or switch in the virtual


environment.
Command: - virtualenv env

Step 4: - After installing virtual environment. Activate


environment using below the command and hit enter.
Command: - .\enviroment\Scripts\activate.ps1
OR
Shortcut key: - E-tab-S-tab-A-tab-tab-4time tab (For ps1) hit Enter

After activation, you will see an error which will be due to


non-setting of policies.

Step 5: - Run the below code on terminal to fix the


error.
Command: - Set-ExecutionPolicy Unrestricted -Scope Process
And run the previous code again. Then you will see that
your error has been resolved now you will enter the
enviroment.

Step 6: - Install the Flask under the enviroment.


Command: - pip install flask
Now has set up the Flask virtual environment.
CREATE A PROJECT
Step 1: - Create a new file outside of enviroment file
name like app.py for creating a new project.

Step 2: - After creating a new file you can write the


code under the file.
Step 8: - Run the code file from here

Step 9: - After run the code you will see the URL you
can Ctrl+click on the Link.
Now you can see the result on the web browser.

HTML FILE WITH FLASK


Step 1: - Create a new Folder named Template.

Step 2: - Then Create a new HTML file inside the Templates


folder and write html code in the file.
Step 3: - Open app.py file and add render_template and
return render_tamplate.

Step 3: - Run the file with flask and click on URL link
(127.0.0.1:5000).

After click on it you will redirect on the server.


CONNECTION WITH DATABASE
Step 1: - Open MySQL workbench and create a database,
use the database and create a table.

Step 2: - Now install the MySQL in flask.


Command: - pip install flask_mysqldb
Step 3: - Create a login form inside the templates folder
(index.html).

Step 4: - Now go to app.py file and write the connectivity


code.
Step 5: - Then run the server and fill the data in the created
form.

Then Click on submit button and you will see your data is
submitted.
Step 6: - Open mysql workbench and run the select * from
tableName command and then you will see your data is
inserted in the table successfully.

You might also like