KEMBAR78
python_basics.pptx basics of python .ppt
Role of Programming language in Mechanical Engineering
• Numerical Analysis and Simulation:
• Libraries like NumPy and SciPy facilitate complex numerical computations, enabling
engineers to perform finite element analysis (FEA), computational fluid dynamics
(CFD), and other simulations for design validation and performance prediction.
• Automation of Repetitive Tasks:
• Python can automate tedious tasks such as data parsing, report generation, and file
manipulation, freeing up engineers to focus on more complex problem-solving.
• Data Analysis and Visualization:
• Libraries like Pandas, Matplotlib, and Seaborn provide powerful tools for analyzing
large datasets from experiments, sensors, or simulations, and for creating insightful
visualizations to understand trends and patterns.
• Design Optimization:
• Python can be used to implement optimization algorithms (e.g., using libraries like
DEAP or Optuna) to refine designs, explore design spaces, and identify optimal
solutions for performance, cost, or other criteria.
• Integration with CAD Software:
• Python can interface with Computer-Aided Design (CAD) software, allowing
engineers to script and automate 3D model generation, modify designs
parametrically, and streamline the design-to-analysis workflow.
• Control and Robotics:
• Python, particularly with platforms like Raspberry Pi, can be used to control motors
and actuators, collect data from sensors, and develop applications for robotics and
automation systems.
• Machine Learning and AI:
• Python's extensive machine learning libraries enable applications like predictive
maintenance, quality control, and optimization of manufacturing processes,
leveraging data to improve system performance and reliability.
• Internet of Things (IoT) Integration:
• Python facilitates the integration of IoT devices in mechanical systems, allowing for
remote monitoring, data collection, and control of equipment.
Introduction
• Python is a dynamic and general-purpose programming language
that is used in various fields.
• Python is used for everything from throwaway scripts to large,
scalable web servers that provide uninterrupted service 24/7.
• It is used for GUI and database programming, client- and server-
side web programming, and application testing.
• It is used by scientists writing applications for the world’s fastest
supercomputers and by children first learning to program.
• It was initially developed in the early 1990s by Guido van Rossum
and is now controlled by the not-for-profit Python Software
Foundation, sponsored by Microsoft, Google, and others.
Basic Features of Python:
• Python provides numerous features:
• Easy to learn and use: Python uses an elegant syntax, making the programs
easy to read. It is developer- friendly and is a high-level programming language.
• Expressive: The Python language is expressive, which means it is more
understandable and readable than other languages.
• Interpreted: Python is an interpreted language. In other words, the
interpreter executes the code line by line. This makes debugging easy and thus
suitable for beginners.
• Cross-platform: Python can run equally well on different platforms such as
Windows, Linux, Unix, Macintosh, and so on. So, Python is a portable language.
• Free and open source: The Python language is freely available at
www.python.org.
• Object-oriented: Python is an object-oriented language with concepts of
classes and objects.
• Extensible: It is easily extended by adding new modules implemented in
a compiled language such as C or C++, which can be used to compile the
code.
• Large standard library: It comes with a large standard library that
supports many common programming tasks such as connecting to web
servers, searching text with regular expressions, and reading and
modifying files.
• GUI programming support: Graphical user interfaces can be developed
using Python.
• Integrated: It can be easily integrated with languages such as C, C++,
Java, and more.
Data Variables in Python
• Python Variable is containers that store values. Python is not “statically typed”.
Therefore, it is not needed to declare variables before using them or declare
their type. A variable is created at the moment when the value is assigned to it.
• A Python variable is a name given to a memory location. It is the basic unit of
storage in a program.
• Rules for Python variables
• A Python variable name must start with a letter or the underscore character.
• A Python variable name cannot start with a number.
• A Python variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and).
• Variable in Python names are case-sensitive (name, Name, and NAME are three
different variables).
• The reserved words (keywords) in Python cannot be used to name the variable
in Python.
Data type in python
• The basic data types in Python include
integers, floats, Boolean, and strings.
• Python has the following data types built-in by
default, in these categories:
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
• List: List is an ordered and indexed collection of values
that are changeable and allows duplicates.
• Tuple: Tuple is an ordered collection of values that are
unchangeable and allows duplicates.
• Set: Set is an unordered collection of values that are
changeable and does not allow duplicates.
• Dict (Dictionary): Dictionaries are used to store data
values in key:value pairs.
• A dictionary is a collection which is ordered,
changeable and do not allow duplicates.
Now a days blob data is also used:
• Python – Read blob object in python using wand library:
• BLOB stands for Binary Large OBject.
• A blob is a data type that can store binary data. This is
different than most other data types used in databases, such
as integers, floating point numbers, characters, and strings,
which store letters and numbers.
• BLOB is a large complex collection of binary data which is
stored in Database. Basically, BLOB is used to store media
files like images, video and audio files. Due to its ability to
store multimedia files it takes a huge disk space. BLOB
provides fast multimedia transfer.
Basic Operators in Python
Operators are the constructs that can manipulate the value
of operands. Like different programming languages, Python
supports the following operators:
• Arithmetic operators
• Relational operators
• Assign operators
• Logical operators
• Membership operators
• Identity operators
• Bitwise operators
Arithmetic Operators:
• An arithmetic operator is a symbol that
performs a mathematical operation on one or
more operands.
Relational operators:
• Relational Operators in python compare the operand
values on either side. The relational operators in Python
return a boolean value,i.e.,either True or False based on the
value of operands
Assign Operator:
• The simple assign operator is the most commonly used operator in Python.
• It is used to assign a value to a variable. The syntax for the simple assignment
operator is: variable = value.
• Here, the value on the right-hand side of the equals sign is assigned to the
variable on the left-hand side. For example,
a = 25.
Logical Operator:
• Logical operators in Python combine two or more operands
and conduct logical comparisons on them. There are three
types, i.e., AND, OR, and NOT. They return a boolean value,
i.e., True or False
Identity operator:
• Identity operators are used to compare the
objects, not if they are equal, but if they are
actually the same object, with the same
memory location:
• Example:
• x = [“shaft", “gear"]
• y = [“shaft", “gear"]
• z = x
• print(x is y)
• # returns False because x is not the same object as y, even if they have the
same content
• print(x == y)
• # to demonstrate the difference betweeen "is" and "==": this comparison
returns True because x is equal to y
• print (x is z)
• # returns True because z is the same object as x
• Q. A cashier has currency notes of
denominations 5,10, 50 and 100. If the
amount to be withdrawn is input through the
keyboard, write a program to find the total
number of currency notes of each
denomination the cashier will have to give to
the withdrawer.
amount=int(input('enter the amount:'))
• Copmuting torque and workdone
• Computing turning moment in slider crank
mechanism

python_basics.pptx basics of python .ppt

  • 1.
    Role of Programminglanguage in Mechanical Engineering • Numerical Analysis and Simulation: • Libraries like NumPy and SciPy facilitate complex numerical computations, enabling engineers to perform finite element analysis (FEA), computational fluid dynamics (CFD), and other simulations for design validation and performance prediction. • Automation of Repetitive Tasks: • Python can automate tedious tasks such as data parsing, report generation, and file manipulation, freeing up engineers to focus on more complex problem-solving. • Data Analysis and Visualization: • Libraries like Pandas, Matplotlib, and Seaborn provide powerful tools for analyzing large datasets from experiments, sensors, or simulations, and for creating insightful visualizations to understand trends and patterns. • Design Optimization: • Python can be used to implement optimization algorithms (e.g., using libraries like DEAP or Optuna) to refine designs, explore design spaces, and identify optimal solutions for performance, cost, or other criteria.
  • 2.
    • Integration withCAD Software: • Python can interface with Computer-Aided Design (CAD) software, allowing engineers to script and automate 3D model generation, modify designs parametrically, and streamline the design-to-analysis workflow. • Control and Robotics: • Python, particularly with platforms like Raspberry Pi, can be used to control motors and actuators, collect data from sensors, and develop applications for robotics and automation systems. • Machine Learning and AI: • Python's extensive machine learning libraries enable applications like predictive maintenance, quality control, and optimization of manufacturing processes, leveraging data to improve system performance and reliability. • Internet of Things (IoT) Integration: • Python facilitates the integration of IoT devices in mechanical systems, allowing for remote monitoring, data collection, and control of equipment.
  • 3.
    Introduction • Python isa dynamic and general-purpose programming language that is used in various fields. • Python is used for everything from throwaway scripts to large, scalable web servers that provide uninterrupted service 24/7. • It is used for GUI and database programming, client- and server- side web programming, and application testing. • It is used by scientists writing applications for the world’s fastest supercomputers and by children first learning to program. • It was initially developed in the early 1990s by Guido van Rossum and is now controlled by the not-for-profit Python Software Foundation, sponsored by Microsoft, Google, and others.
  • 4.
    Basic Features ofPython: • Python provides numerous features: • Easy to learn and use: Python uses an elegant syntax, making the programs easy to read. It is developer- friendly and is a high-level programming language. • Expressive: The Python language is expressive, which means it is more understandable and readable than other languages. • Interpreted: Python is an interpreted language. In other words, the interpreter executes the code line by line. This makes debugging easy and thus suitable for beginners. • Cross-platform: Python can run equally well on different platforms such as Windows, Linux, Unix, Macintosh, and so on. So, Python is a portable language. • Free and open source: The Python language is freely available at www.python.org.
  • 5.
    • Object-oriented: Pythonis an object-oriented language with concepts of classes and objects. • Extensible: It is easily extended by adding new modules implemented in a compiled language such as C or C++, which can be used to compile the code. • Large standard library: It comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, and reading and modifying files. • GUI programming support: Graphical user interfaces can be developed using Python. • Integrated: It can be easily integrated with languages such as C, C++, Java, and more.
  • 6.
    Data Variables inPython • Python Variable is containers that store values. Python is not “statically typed”. Therefore, it is not needed to declare variables before using them or declare their type. A variable is created at the moment when the value is assigned to it. • A Python variable is a name given to a memory location. It is the basic unit of storage in a program. • Rules for Python variables • A Python variable name must start with a letter or the underscore character. • A Python variable name cannot start with a number. • A Python variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and). • Variable in Python names are case-sensitive (name, Name, and NAME are three different variables). • The reserved words (keywords) in Python cannot be used to name the variable in Python.
  • 7.
    Data type inpython • The basic data types in Python include integers, floats, Boolean, and strings. • Python has the following data types built-in by default, in these categories: Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview None Type: NoneType
  • 8.
    • List: Listis an ordered and indexed collection of values that are changeable and allows duplicates. • Tuple: Tuple is an ordered collection of values that are unchangeable and allows duplicates. • Set: Set is an unordered collection of values that are changeable and does not allow duplicates. • Dict (Dictionary): Dictionaries are used to store data values in key:value pairs. • A dictionary is a collection which is ordered, changeable and do not allow duplicates.
  • 9.
    Now a daysblob data is also used: • Python – Read blob object in python using wand library: • BLOB stands for Binary Large OBject. • A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating point numbers, characters, and strings, which store letters and numbers. • BLOB is a large complex collection of binary data which is stored in Database. Basically, BLOB is used to store media files like images, video and audio files. Due to its ability to store multimedia files it takes a huge disk space. BLOB provides fast multimedia transfer.
  • 10.
    Basic Operators inPython Operators are the constructs that can manipulate the value of operands. Like different programming languages, Python supports the following operators: • Arithmetic operators • Relational operators • Assign operators • Logical operators • Membership operators • Identity operators • Bitwise operators
  • 11.
    Arithmetic Operators: • Anarithmetic operator is a symbol that performs a mathematical operation on one or more operands.
  • 12.
    Relational operators: • RelationalOperators in python compare the operand values on either side. The relational operators in Python return a boolean value,i.e.,either True or False based on the value of operands
  • 13.
    Assign Operator: • Thesimple assign operator is the most commonly used operator in Python. • It is used to assign a value to a variable. The syntax for the simple assignment operator is: variable = value. • Here, the value on the right-hand side of the equals sign is assigned to the variable on the left-hand side. For example, a = 25.
  • 14.
    Logical Operator: • Logicaloperators in Python combine two or more operands and conduct logical comparisons on them. There are three types, i.e., AND, OR, and NOT. They return a boolean value, i.e., True or False
  • 15.
    Identity operator: • Identityoperators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location:
  • 16.
    • Example: • x= [“shaft", “gear"] • y = [“shaft", “gear"] • z = x • print(x is y) • # returns False because x is not the same object as y, even if they have the same content • print(x == y) • # to demonstrate the difference betweeen "is" and "==": this comparison returns True because x is equal to y • print (x is z) • # returns True because z is the same object as x
  • 17.
    • Q. Acashier has currency notes of denominations 5,10, 50 and 100. If the amount to be withdrawn is input through the keyboard, write a program to find the total number of currency notes of each denomination the cashier will have to give to the withdrawer. amount=int(input('enter the amount:'))
  • 18.
    • Copmuting torqueand workdone • Computing turning moment in slider crank mechanism