0% found this document useful (0 votes)
28 views62 pages

112556336-Python 1

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. It can be used for a wide range of applications including data science, web development, game development, and more. The Python course for aerospace engineering students will teach skills useful for tasks like scripting, data analysis, software development, algorithm design, testing, and more that are applicable to jobs in the aerospace industry.

Uploaded by

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

112556336-Python 1

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. It can be used for a wide range of applications including data science, web development, game development, and more. The Python course for aerospace engineering students will teach skills useful for tasks like scripting, data analysis, software development, algorithm design, testing, and more that are applicable to jobs in the aerospace industry.

Uploaded by

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

PYTHON

COURSE CODE : 22CSIESPYP


PYTHON

●Python is an
○ Interpreted,
○ Object-oriented,
○ High-level programming language with dynamic
semantics

What is Python? Executive Summary | Python.org


Why to study PYTHON

Ref:
● Programming Languages Ranking: Top 9 in 2023 - DistantJob - Remote Recruitment Agency
● Programming language rankings: JavaScript still rules, Python holds off Java | ZDNET
● PYPL PopularitY of Programming Language index
Python programming is a general-purpose skill used in
almost all fields

● Datascience
● Scientific and Mathematical computing
● Web development
● Finance and Trading
● System automation and trading
● Computer graphics
● Basic game development
● Security and penetration testing
● General and application-specific scripting
● Mapping and Geography
And many more………
Why Aerospace Engineering students has to
read this subject?.....
As a programmer in the aerospace industry, the duties in your job description will vary. There are many
different types of projects to work on, such as:

● Scripting to generate automation tasks or documentation


● Performing data analysis with software
● Developing software simulations
● Working on algorithm design
● Automated testing for verification purposes
● Writing embedded flight software
● Developing new features for aerospace electronics
And much more..
SYLLABUS
AAT DETAILS
● A group of 3 students will be formed and instructed to develop any one of the
following:
○ Python application such as CGPA/SGPA calculator, Receipt generation for different
business domains.
○ Games using Python programming.

● The student will be evaluated on the following parameters:


○ Presentation and demonstration
○ Report submission
○ The evaluation will be conducted for 20M which will be reduced to 5M
Lab Evaluation(25 Marks)

● Lab Test: 15 marks


• Write up – 4 marks
• Execution – 6 marks
• Viva – 5 marks

● CIE: 10 marks
• Record - 3 marks
• Writeup – 2 marks
• Execution – 4 marks
• Demonstration - 1 mark
Python Download Link

● https://www.python.org/downloads/release/python-390/
Large User INTERPRETE
Community D

FREE AND Extensive


OPEN EASY LIBRARY
SOURCE

OBJECT
PORTABLE ORIENTED

Features of python
Value

●If you want to know what type value a variable contains


then use type method
>>> type(10) >>>type('BMSCE') >>> type('3.2')
<class 'int'> <class 'str’> <class 'str'>

>>> type('17') >>> type(3.2)


<class 'str'> <class 'float'>
● Variable:
One of the most powerful features of a programming language is the ability to manipulate variables.
A variable is a name that refers to a value.
Ex: number,rate,volume
● A variable should start with alphabet
● It can have a combination of number,alphabet,underscore
Which of the variable name are correct?

more@ Class

number_1

total 6trombones
Keywords
Python reserves 35 keywords…
Statements

● A statement is a unit of code that the Python interpreter can execute.


● A script usually contains a sequence of statements
● Example:

print(1)
x=2
print(x)

Output:
1
2
Exercise:
1. Write a simple program to print BMSCE.
2. Write a program to create a variable with meaning and print the result
3. A retail store management wants to automate the process of generating bill amount for its customers. As in
initial step, they want to initialize the bill details of a customer as given below:
Bill Id should be 1 and customer Id must be 10 and bill amount amount is 500.00.
After initializing all the values must be displayed using print function.
4. Identify the previous program data types that are used to represent the bill.
5. Write a program to convert kg to pounds?
1kg=2.205lb
6. Write a program to convert height cm to inches?
Formula:divide the given input/2.54
7. Write a program to calculate BMI given height in cm and weight in kg
( BMI=703*weight in pounds/(height in inches) 2)

8. Write a program to calculate the run rate of the team.


a. Take input of the total score and no of overs
b. Formula=total score by batting team/total overs
9. The Problem: A hole has a diameter of 80mm and a tolerance of -0.102 and +0.222. Determine the minimum and
maximum dimensions of this hole using python IDLE
Operators and operands
OPERATORS and OPERANDS

● Operators and Operands


○ Operators are special symbols that represent computations like addition and multiplication .
■ Arithmetic operators
■ Comparison operators
■ Logical operators
■ Bitwise operators
■ Identity operators
○ The values the operator is applied to are called operands.
Arithmetic operators
The result of the standard
division is always float
When the result of floor division (//) is positive, it is as though
the fractional portion is truncated off, leaving only the
integer portion.

When the result is negative, the result is rounded


down to the next smallest (greater negative)
integer
Few more examples….

INPUT OUTPUT
print(10//3) 3
print(-5//2) -3
print(5.0//2) 2.0
print(-5.0//2) -3.0
Precedence of Arithmetic Operators in Python

The precedence of Arithmetic Operators in python is as follows:

1. P – Parentheses
2. E – Exponentiation
3. M – Multiplication (Multiplication and division have the same
precedence)
4. D – Division
5. A – Addition (Addition and subtraction have the same precedence)
6. S – Subtraction
Comparison Operators in Python
● The preferred way to determine whether two floating-point values are “equal” is to
compute whether they are close to one another, given some tolerance.
Example:

a=13 b=133
print(a > b) False

print(a < b) True

print(a == b) False

print(a != b) True

print(a >= b) False

print(a <= b) True


Logical Operators in Python
Bitwise Operators
x=1 y=2
print(x&y)
Output: 0

print(x|y)
Output:3

print(~x)
Output:-2

print(x^y)
Output:3

print(x>>2)
Output:0

print(x<<2)
Output:4
Identity Operator

● is
● is not

determine whether the


given operands have the
same identity—that is,
refer to the same object.
String operations
● The + operator works with strings, but it is not addition in the
mathematical sense.
● Instead it performs concatenation, which means joining the strings by
linking them end to end

>>> first = 10 >>> first = '100'


>>> second = 15
>>>
>>> second = '150'
print(first+second) >>> print(first + second)
25 100150
The output of this program is
100150.
Syntax: Conditional Statements
Simple if:

if(condition):
Ex: True
x=12
block
if(x>0):

print(‘x is positive’)
Conditional Statements…..

● There is no limit on the number of statements that can


appear in the body, but there must be at least one.
● In few scenario, where there is no statement that
appear in the body then we can use pass statement
Example:
if x < 0 :
pass
Another scenario is
if x>10:
print('Expression was true')
if <expr>:
print('Executing statement in suite')
<statement> print('...')
<statement> print('Done.')
... print('After conditional')
<statement> Output:
<following_statement> Expression was true
Executing statement in suite

Done
After Conditional
if else

if(number>0):
Syntax:
print(“positive”)
else:
if condition1: print(“negative”)
statements
else:
statements
For Example:

if x%2 == 0 :
print('x is even')
else :
print('x is odd')
CHAINED CONDITION..
● Sometimes there are more than two possibilities and we need more than two
branches.
● One way to express a computation like that is a chained conditional:

if x < y:

print('x is less than


y')
elif x > y:
print('x is greater
than y')
else:
print('x and y are
equal')
EX:BMI Calculator

BMI Categories:
● Underweight = <18.5
● Normal weight = 18.5–24.9
● Overweight = 25–29.9
● Obesity = BMI of 30 or greater
Ref:BMI Calculator – with cm & kg
Excersice
1. Write a python program to check whether the student is eligible for Sem end exam
2. Write a python program to take input for a subject three internal marks and select best two among them
and print them
3. Write a python program to check whether the student is eligible for fasttrack or not?

Fasttrack constraints.

a. Student if don’t qualify in lab cie or theory cie or if u fail sem end or attendance shortage
b. If it is a lab subject ,student should get min 10m in lab and 10 marks in theory for cie,and for sem end min 40
marks for 100
c. If it is not alab subject,he /she should score 20 in theory for cie,and for sem end min 40 marks for 100
4. Write a python program to check whether the student is eligible for makeup exam or not?

MAKE UP..

a. The student has 45+ for 50,but not qualified in sem end
5. Write a python program to check whether you are eligible to vote or not? Your program should get the age of the
voter from the user and if their age is 18 and above, let them vote otherwise deny them from voting.
6 Write a python program that will check for the following conditions:
■ If the light is green – Car is allowed to go
■ If the light is yellow – Car has to wait
■ If the light is red – Car has to stop
■ Other signal – unrecognized signal. Example black, blue, etc…

7 Write a program to check students’ grades. Your program should fulfill the following conditions:
● Grade A – Outstanding
● Grade B – Excellent
● Grade C – Very Good
● Grade D – Good
● Grade E – Satisfactory
● Grade F– UnSatisfactory

A program should also ask to enter the student’s name, class, and section.
Nested conditionals

One conditional can also be nested within another.


For Example:

if x == y:
print('x and y are equal')
else:
if x < y:
print('x is less than y')
else:
print('x is greater than y')
Exercise:

1. Modify the earlier program (7th Program) students’ grades in such a way that they
should take in five subject marks. Find the total mark and their percentage. Your
program should check for the following conditions:
a. If the percentage falls below 40, they are considered to fail.
b. If the percentage is between 40 and 60, grade them as pass.
c. If the percentage is between 60 and 75, grade them as good.
d. If the percentage is between 75 and 85, grade them as very good.
e. If the percentage is between 85 and 100, grade them excellent.
f. If the percentage is below zero or above 100, it’s an error.
Note: Demonstrate nested condition
Catching exceptions using try and except

output:
enter a number:3
Traceback (most recent call last):
File
"C:/Users/BMSCECSE/AppData/Local/Programs/Python/Python311/s2.py", line
2, in <module>
x=x+1
TypeError: can only concatenate str (not "int") to str
>>>
try:
x=input("enter a number:")
x=x+1
print(x)
except:
print("invalid input")

=== RESTART:
C:/Users/BMSCECSE/AppData/Local/Prog
rams/Python/Python311/s2.py ===
enter a number:3
invalid input
try:
x=input("enter a number:")
x=x+1
print(x)
except:
print("invalid input")
finally:
print("I will be printed all the
time")

output:
enter a number:4
invalid input
I will be printed all the time

You might also like