0% found this document useful (0 votes)
5 views

MP 1 Arsd Lecture1

Uploaded by

sciyasingh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

MP 1 Arsd Lecture1

Uploaded by

sciyasingh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Lecture 1

10-Sept-2024
on
“Python Basics”

Mathematical Physics -1
By
Prof. Vinita Tuli
Prof. Anjali Kaushik
Shivnandi
Sneh
What is Python?
1. Python is a popular programming language. It
was created by Guido van Rossum, and
released in 1991.
2. It is used for:
1. web development (server-side),
2. software development,
3. mathematics,
4. system scripting.
3. What can Python do?
1. Python can be used on a server to create
web applications.
2. Python can be used alongside software to
create workflows.
3. Python can connect to database systems.
It can also read and modify files.
4. Python can be used to handle big data and
perform complex mathematics.
5. Python can be used for rapid prototyping,
or for production-ready software
development Ref: W3schools.com
What is Python?

➢ Python is an interpreted language


➢ Run code in Python shell (interactive mode) or by
running scripts
➢ Example of using the Python interpreter: >>>
print("Hello, World!")
➢ The Zen of Python:

import this

Ref: W3schools.com
import sys
print(sys.version)
Python as Calculator
➢ An arithmetic operation includes addition, subtraction, multiplication, division, or
powers between two numbers. An arithmetic operator is a symbol that Python has
reserved to mean one of the operations above. These symbols are + for addition, -
for subtraction, * for multiplication, / for division, and ** for exponential.

➢ TRY IT! Compute the sum of 1 and 2.


3∗4
➢ TRY IT! Compute 3 8
2 +2
➢ TRY IT! Compute 3 divided by 4, then multiply the result by 2, and then
raise the result to the 3rd power
➢ In [3]: 3/4
➢ In [4]: _*2
➢ In [5]: _**3
Python as Calculator
➢ TRY IT! import math
➢ TRY IT! Compute math.sqrt(4)
➢ TRY IT! Compute math.sin(math.pi/2)
➢ TRY IT! Compute math.exp(math.log(10))
➢ TRY IT! Compute math.exp(3/4)

➢ TRY IT! math.factorial?


➢ TRY IT! 1/0
➢ TRY IT! 1/math.inf
➢ TRY IT! math.inf * 2
➢ TRY IT! math.inf/math.inf
➢ TRY IT! complex(2,5)
Comparison Operaters

➢ TRY IT! type(1234)


➢ TRY IT! type(3.14)
➢ TRY IT! type(2 + 5j)

➢ TRY IT! 5 == 4
➢ TRY IT! 2 < 3
Logical operaters

➢ TRY IT! (1 and not 0) or (1 and 0)


➢ TRY IT! 1 + 3 > 2 + 5
➢ TRY IT! (3 > 2) + (5 > 4)
Problems

➢ Print “I love Python” using Python Shell.


➢ Compute the area of a triangle with base 10 and height 12. Recall that the
area of a triangle is half the base times the height.
➢ Compute the surface area and volume of a cylinder with radius 5 and height
3.
➢ Use Python’s factorial function to compute 6!
➢ Compute the sin87°.

You might also like