112556336-Python 1
112556336-Python 1
●Python is an
○ Interpreted,
○ Object-oriented,
○ High-level programming language with dynamic
semantics
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:
● 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
OBJECT
PORTABLE ORIENTED
Features of python
Value
more@ Class
number_1
total 6trombones
Keywords
Python reserves 35 keywords…
Statements
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)
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
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) False
print(a != b) True
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
if(condition):
Ex: True
x=12
block
if(x>0):
print(‘x is positive’)
Conditional Statements…..
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:
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
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