Learning Professional Python Volume 1 The Basics
Usharani Bhimavarapu Jude D Hemanth download
https://ebookbell.com/product/learning-professional-python-
volume-1-the-basics-usharani-bhimavarapu-jude-d-hemanth-51748680
Explore and download more ebooks at ebookbell.com
Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Learning Professional Python Volume 1 The Basics Usharani Bhimavarapu
https://ebookbell.com/product/learning-professional-python-
volume-1-the-basics-usharani-bhimavarapu-52247758
Machine Learning With Python For Everyone 1st Edition Mark E Fenner
https://ebookbell.com/product/machine-learning-with-python-for-
everyone-1st-edition-mark-e-fenner-11035230
Machine Learning With Python For Everyone First Edition Mark Fenner
https://ebookbell.com/product/machine-learning-with-python-for-
everyone-first-edition-mark-fenner-61035860
Machine Learning With Python For Everyone First Edition Mark Fenner
https://ebookbell.com/product/machine-learning-with-python-for-
everyone-first-edition-mark-fenner-49849824
Machine Learning Guide For Oil And Gas Using Python A Stepbystep
Breakdown With Data Algorithms Codes And Applications Hoss Belyadi
https://ebookbell.com/product/machine-learning-guide-for-oil-and-gas-
using-python-a-stepbystep-breakdown-with-data-algorithms-codes-and-
applications-hoss-belyadi-46461796
Foundations Of Deep Reinforcement Learning Theory And Practice In
Python Laura Graesser Wah Loon Keng
https://ebookbell.com/product/foundations-of-deep-reinforcement-
learning-theory-and-practice-in-python-laura-graesser-wah-loon-
keng-49136296
Foundations Of Deep Reinforcement Learning Theory And Practice In
Python 1st Edition Laura Graesser
https://ebookbell.com/product/foundations-of-deep-reinforcement-
learning-theory-and-practice-in-python-1st-edition-laura-
graesser-22282070
Foundations Of Deep Reinforcement Learning Theory And Practice In
Python First Edition Laura Graesser Wah Loon Keng
https://ebookbell.com/product/foundations-of-deep-reinforcement-
learning-theory-and-practice-in-python-first-edition-laura-graesser-
wah-loon-keng-11843600
Python For Professionals Learning Python As A Second Language Matt
Telles
https://ebookbell.com/product/python-for-professionals-learning-
python-as-a-second-language-matt-telles-44786054
Learning Professional
Python
Volume 1 of Learning Professional Python is a resource for students who
want to learn Python even if they don’t have any programming knowledge
and for teachers who want a comprehensive introduction to Python to use
with their students. This book helps the students achieve their dream job
in the IT Industry and teaches the students in an easy, understandable
manner while strengthening coding skills.
Learning Professional Python: Volume 1 Objectives
• Become familiar with the features of Python programming language
• Introduce the object-oriented programming concepts
• Discover how to write Python code by following the object-oriented
programming concepts
• Become comfortable with concepts such as classes, objects, inheritance,
dynamic dispatch, interfaces, and packages
• Learn the Python generics and collections
• Develop exception handling and the multithreaded applications
• Design graphical user interface (GUI) applications
CHAPMAN & HALL/CRC THE PYTHON SERIES
About the Series
Python has been ranked as the most popular programming language, and
it is widely used in education and industry. This book series will offer a
wide range of books on Python for students and professionals. Titles in the
series will help users learn the language at an introductory and advanced
level, and explore its many applications in data science, AI, and machine
learning. Series titles can also be supplemented with Jupyter notebooks.
Image Processing and Acquisition using Python, Second Edition
Ravishankar Chityala, Sridevi Pudipeddi
Python Packages
Tomas Beuzen and Tiffany-Anne Timbers
Statistics and Data Visualisation with Python
Jesús Rogel-Salazar
Introduction to Python for Humanists
William J.B. Mattingly
Python for Scientific Computation and Artificial Intelligence
Stephen Lynch
Learning Professional Python: Volume 1: The Basics
Usharani Bhimavarapu and Jude D. Hemanth
Learning Professional Python: Volume 2: Advanced
Usharani Bhimavarapu and Jude D. Hemanth
For more information about this series please visit: www.crcpress.com/
Chapman – HallCRC/book-series/PYTH
Learning Professional
Python
Volume 1: The Basics
Usharani Bhimavarapu
and Jude D. Hemanth
Cover Image Credit: Shutterstock.com
First edition published 2024
by CRC Press
2385 NW Executive Center Drive, Suite 320, Boca Raton, FL 33431
and by CRC Press
4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
CRC Press is an imprint of Taylor & Francis Group, LLC
© 2024 Usharani Bhimavarapu and Jude D. Hemanth
Reasonable efforts have been made to publish reliable data and
information, but the author and publisher cannot assume responsibility
for the validity of all materials or the consequences of their use. The
authors and publishers have attempted to trace the copyright holders of
all material reproduced in this publication and apologize to copyright
holders if permission to publish in this form has not been obtained. If
any copyright material has not been acknowledged please write and let us
know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be
reprinted, reproduced, transmitted, or utilized in any form by any electronic,
mechanical, or other means, now known or hereafter invented, including
photocopying, microfilming, and recording, or in any information storage
or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this
work, access www.copyright.com or contact the Copyright Clearance
Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978–750–8400. For works that are not available on CCC please contact
[email protected]
Trademark notice: Product or corporate names may be trademarks or
registered trademarks and are used only for identification and explanation
without intent to infringe.
Library of Congress Cataloging‑in‑Publication Data
Names: Bhimavarapu, Usharani, author. | Hemanth, D. Jude, author.
Title: Learning professional Python / Usharani Bhimavarapu, D. Jude Hemanth.
Description: First edition. | Boca Raton : CRC Press, 2024. | Includes
bibliographical references and index.
Identifiers: LCCN 2023007977 | ISBN 9781032539256 (volume 1 ; hbk) |
ISBN 9781032534237 (volume 1 ; pbk) | ISBN 9781003414322
(volume 1 ; ebk) | ISBN 9781032611761 (volume 2 ; hbk) | ISBN
9781032611709 (volume 2 ; pbk) | ISBN 9781003462392 (volume 2 ; ebk)
Subjects: LCSH: Python (Computer program language) | Computer
programming.
Classification: LCC QA76.73.P98 B485 2024 | DDC 005.13/3—dc23/eng/
20230508
LC record available at https://lccn.loc.gov/2023007977
ISBN: 978-1-032-53925-6 (hbk)
ISBN: 978-1-032-53423-7 (pbk)
ISBN: 978-1-003-41432-2 (ebk)
DOI: 10.1201/9781003414322
Typeset in Minion
by Apex CoVantage, LLC
Contents
Preface, xi
Author Biographies, xiii
Chapter 1 ◾ Python Basics 1
1.1 HISTORY OF PYTHON 1
1.2 ADVANTAGES OF PYTHON 1
1.3 CHARACTERISTICS OF PYTHON 2
1.4 APPLICATIONS OF PYTHON 2
1.5 PYTHON VERSIONS 3
1.6 PYTHON IDENTIFIERS 3
1.7 RESERVED WORDS 3
1.8 PRINT () FUNCTION 4
1.9 LINES AND INDENTATION 7
1.10 MULTILINE STATEMENTS 7
1.11 QUOTATION IN PYTHON 8
1.12 COMMENTS IN PYTHON 8
1.13 MULTIPLE STATEMENTS ON A SINGLE LINE 9
1.14 PYTHON VARIABLES 10
1.15 NAMING CONVENTIONS TO VARIABLES 10
1.16 ASSIGNING VALUES TO VARIABLES 11
1.17 MULTIPLE ASSIGNMENT 12
1.18 NONE VARIABLE 13
1.19 DATA TYPES 13
v
vi ◾ Contents
1.20 TYPE CONVERSION 14
1.20.1 Implicit Conversion 14
1.20.2 Explicit Conversion 15
1.21 LITERALS 16
1.22 BINARY NUMBER SYSTEM 17
EXERCISE 17
Chapter 2 ◾ Python Operators 19
2.1 OPERATORS INTRODUCTION 19
2.1.1 Unary Operators 19
2.1.2 Binary Operator 19
2.1.3 Ternary Operator 19
2.2 BINARY OPERATORS 20
2.2.1 Arithmetic Operators 20
2.2.2 Shortened Operators 22
2.3 STRING OPERATORS 26
2.4 OPERATOR PRECEDENCE 27
2.5 EXPRESSION EVALUATION 28
2.6 INPUT () FUNCTION 29
2.7 LIBRARIES 33
2.7.1 Math and CMath Libraries 33
2.7.2 SciPy Library 36
EXERCISE 37
Chapter 3 ◾ Decision-Making and Conditionals 41
3.1 INTRODUCTION 41
3.2 IF STATEMENT 41
3.3 IF-ELSE STATEMENT 43
3.4 NESTED-IF-ELSE STATEMENT 44
3.5 ELIF STATEMENT 46
3.6 WHILE 48
3.7 FOR LOOP 49
3.8 NESTED FOR LOOPS 52
Contents ◾ vii
3.9 NESTED WHILE 54
3.10 USING ELSE STATEMENT WITH FOR LOOP 55
3.11 THE PASS STATEMENT IN FOR LOOP 56
3.12 BREAK STATEMENT 56
3.13 CONTINUE 58
3.14 WHILE LOOP AND THE ELSE BRANCH 60
EXERCISE 74
Chapter 4 ◾ Strings75
4.1 STRING CREATION 75
4.2 ACCESSING VALUES TO A STRING 76
4.3 MODIFY EXISTING STRING 78
4.4 ESCAPE CHARACTERS 79
4.5 STRING SPECIAL CHARACTERS 80
4.6 STRING FORMATTING OPERATOR 81
4.7 TRIPLE QUOTES 84
4.8 UNICODE STRINGS 84
4.9 BUILT-IN STRING METHODS 84
4.10 DELETING STRING 87
EXERCISE 88
Chapter 5 ◾ Lists91
5.1 INTRODUCTION 91
5.2 CHARACTERISTICS OF LISTS 92
5.3 DECISION-MAKING IN LISTS 93
5.3.1 Range 94
5.4 ACCESSING VALUES IN THE LIST 95
5.5 UPDATING LIST 99
5.6 DELETE LIST ELEMENTS 100
5.7 SORTING 100
5.8 COPYING 101
5.9 OPERATORS ON LISTS 102
5.10 INDEXING, SLICING 104
viii ◾ Contents
5.11 SEARCHING IN LIST 105
5.12 NESTED LIST 106
5.13 LIST COMPREHENSION 108
5.14 MATRIX REPRESENTATION 109
EXERCISE 126
Chapter 6 ◾ Tuple127
6.1 TUPLE CREATION 127
6.2 ACCESSING VALUES IN TUPLES 129
6.3 UPDATING TUPLES 132
6.4 DELETE TUPLE ELEMENTS 133
6.5 OPERATIONS ON TUPLES 134
6.6 UNPACKING OF TUPLES 138
6.7 INDEXING, SLICING ON TUPLES 140
EXERCISE 142
Chapter 7 ◾ Sets143
7.1 INTRODUCTION 143
7.2 ACCESS SET ELEMENTS 145
7.3 ADDING ELEMENTS TO THE SET 145
7.4 REMOVE AN ELEMENT FROM THE SET 146
7.5 DELETE THE SET 146
7.6 PYTHON SET OPERATIONS 147
7.7 SET MEMBERSHIP OPERATORS 148
7.8 SET PREDEFINED METHODS 149
7.9 FROZEN SET 152
7.10 FROZEN SET OPERATIONS 153
7.11 FROZEN SET PREDEFINED OPERATIONS 153
EXERCISE 156
Chapter 8 ◾ Dictionary157
8.1 ACCESSING THE ELEMENTS OF THE DICTIONARY 163
8.2 COPYING THE DICTIONARY 165
Contents ◾ ix
8.3 NESTED DICTIONARY 166
8.4 CHANGING THE DICTIONARY VALUES 167
8.5 ADDING THE ELEMENTS TO THE DICTIONARY 168
8.6 REMOVING THE ELEMENTS OF THE DICTIONARY 168
8.7 DICTIONARY COMPREHENSION 169
8.8 OPERATORS IN DICTIONARY 172
EXERCISE 173
Chapter 9 ◾ Modules and Packages 175
9.1 PYTHON IMPORT STATEMENT 175
9.2 PYTHON FROM . . . IMPORT STATEMENT 175
9.3 PACKAGE 183
EXERCISE 187
Chapter 10 ◾ Functions189
10.1 DEFINING A FUNCTION 189
10.2 PASS BY REFERENCE 192
10.3 FUNCTION ARGUMENTS 193
10.3.1 Required Arguments 194
10.3.2 Keyword Arguments 194
10.3.3 Default Arguments 197
10.3.4 Variable Length Arguments 198
10.4 ANONYMOUS FUNCTIONS 199
10.5 RETURN STATEMENT 200
10.6 FUNCTION VARIABLE SCOPE 202
10.7 PASSING LIST TO FUNCTION 206
10.8 RETURNING LIST FROM THE FUNCTION 208
10.9 RECURSION 209
EXERCISE 211
Chapter 11 ◾ Date and Time 213
11.1 TIME MODULE 213
11.2 CALENDAR 214
x ◾ Contents
11.3 TIME MODULE 214
11.4 CALENDAR MODULE 215
11.5 THE DATETIME MODULE 217
11.6 THE PYTZ MODULE 217
11.7 THE DATEUTIL MODULE 218
EXERCISE 238
Chapter 12 ◾ Regular Expression 241
12.1 THE RE MODULE 241
12.2 PYTHON MATCH FUNCTION 243
12.3 THE SEARCH FUNCTIONS 244
12.4 PYTHON MATCH FUNCTION VS SEARCH
FUNCTION246
12.5 THE COMPILE FUNCTION 248
12.6 THE FINDALL () FUNCTION 249
12.7 THE SPLIT () FUNCTION 251
12.8 THE SUB () FUNCTION 252
12.9 THE RE.ESCAPE () FUNCTION 254
EXERCISE 254
INDEX, 255
Preface
P ython is a general-purpose interpreted programming language used
for deep learning, machine learning, and complex data analysis.
Python is a perfect language for beginners as it is easy to learn and under-
stand. This book is intended to teach the reader how to program in Python.
The book aims to get you up to speed fast enough and have you writing
real Python programs in no time at all. It assumes no previous exposure
to the Python language and is suited to both beginners and experienced
programmers. This book gives a comprehensive, in-depth introduction to
the core Python language.
This book helps you in gaining a quick grasp of the fundamentals of
Python programming and working with built-in functions. The book then
moves to help you in exception handling, data wrangling, databases with
Python, regular expressions, NumPy arrays, data frames and plotting. The
Python Programming culminates with how you can continue learning
Python after reading this book and leaves you with a problem to solve,
testing your skills even at the last step.
The book contains approximately 500 tested programs, and all these
programs have been tested using the IDE Anaconda, Google colaboratory,
and Python online compilers compatible to the Windows operating sys-
tem and discussed the appropriate nature of the output. The book further
mentions a summary of the technical aspects of interviewing tips on nego-
tiating the best offer and guiding the best way.
This book is for data analysts, IT developers, and anyone looking to get
started with or transition to the field of software or refresh their knowledge
of Python programming. This book will also be useful for students plan-
ning to build a career in data engineering or IT professionals preparing for
a transition. No previous knowledge of data engineering is required. The
book aims to get you up to speed fast enough and have you writing real
Python programs in no time at all.
xi
xii ◾ Preface
It contains 12 chapters, and at the end of every chapter, practice exer-
cises are given to enable the learners to review the knowledge gained. Each
chapter starts with a brief introduction, top tips, and a review of the essen-
tial library methods, finally followed by broad and thought-provoking
problems.
We are thankful to Taylor and Francis Publications for undertaking the
publication of this book and supporting us in this endeavor. Any sugges-
tions for the improvement of the book will be thankfully acknowledged
and incorporated in the next edition.
Dr. Usharani Bhimavarapu
Dr. Jude D. Hemanth
Author Biographies
Usharani Bhimavarapu is working as an assistant
professor in the Computer Science and Engineering
Department at Koneru Lakshmaiah Education
Foundation at Vaddeswaram, Andhra Pradesh,
India. She has been teaching for the last 14 years with
emphasis on data mining, machine learning, and data
structure. She communicated more than 40 research
papers in SCI, SCIE, and Scopus indexed journals. She
has authored 12 books in programming languages like
CPP, Java, Python, HTML, CSS, and so on.
Dr. Jude D. Hemanth received his BE degree in ECE
from Bharathiar University in 2002, ME degree in
communication systems from Anna University in
2006, and PhD from Karunya University in 2013. His
research areas include computational intelligence and
image processing. He has authored more than 230
research papers in reputed SCIE indexed international
journals and Scopus indexed international confer-
ences. His cumulative impact factor is more than 350.
He has published 37 edited books with reputed publishers such as Elsevier,
Springer, and IET.
He has been serving as an associate editor of SCIE indexed interna-
tional journals such as IEEE Journal of Biomedical and Health Informatics
(IEEE-JBHI), IEEE Transactions on Intelligent Transportation Systems, Soft
Computing (Springer), Earth Science Informatics (Springer), IET Image
Processing, Heliyon (Elsevier), Mathematical Problems in Engineering,
PeerJ Computer Science, PLOS One, and Dyna (Spain). He also holds the
associate editor/guest editor position with many Scopus journals. He
xiii
xiv ◾ Author Biographies
has been serving as the series editor of Biomedical Engineering series
(Elsevier), editorial board member of ASTI series (Springer), and Robotics
and Healthcare series (CRC Press).
He has received a project grant of 35,000 UK pounds from the UK
government (GCRF scheme) with collaborators from the University of
Westminster, UK. He has also completed two funded research proj-
ects from CSIR and DST, the government of India. He also serves as the
research scientist of Computational Intelligence and Information Systems
(CI2S) Lab, Argentina; LAPISCO Research Lab, Brazil; RIADI Lab,
Tunisia; Research Centre for Applied Intelligence, University of Craiova,
Romania; and eHealth and Telemedicine Group, University of Valladolid,
Spain.
He is the NVIDIA university ambassador and NVIDIA certified instruc-
tor for deep learning courses. His name was featured in the “Top 2% Lead
ing World Scientists” [2021, 2022] list released by Stanford University, USA.
He is an international accreditation member for higher education insti-
tutions in Romania [ARACIS] and Slovenia [SQAA] under the European
Commission. Currently, he is working as a professor in the Department of
ECE, Karunya University, Coimbatore, India.
Chapter 1
Python Basics
P ython is a regular general-purpose, high-level, and object-oriented
programming language. Python is an interpreted scripting language.
Python is a simple-to-understand and multipurpose scripting language.
Python is a multipurpose programming language. It can be used with
web, enterprise applications. Python makes the development and the
debugging fast.
1.1 HISTORY OF PYTHON
Python was created by Guido Van Rossum in the early nineteenth cen-
tury at the national research institute for mathematics and computer
science in the Netherlands. Python is obtained from several additional
programming languages like ABC, Modula-3, C, CPP, Smalltalk, Unix,
and scripting languages. Python is accessible under the GNU public
license (GPU)
1.2 ADVANTAGES OF PYTHON
1. Python is interpreted – There is no need to compile the python pro-
gram before executing it.
2. Python is interactive – The developer can relate to the interpreter
immediately to write the python programs.
3. Python is object oriented – Python maintains an object-oriented pro-
gramming concept that encapsulates the code contained by objects.
DOI: 10.1201/9781003414322-1 1
2 ◾ Learning Professional Python
1.3 CHARACTERISTICS OF PYTHON
The important characteristics of Python programming:
1. Python provides a high-level dynamic data type and strengthens
dynamic type checking.
2. Python is opensource; it can contribute to the development code.
3. Python is as understandable as plain English.
4. Python supports functional, structure, as well as object-oriented
programming methods.
5. Python supports automatic garbage collection.
6. Python source code can be converted to the byte code.
7. Easy to learn – Python has a straightforward structure and obviously
defined syntax. It is simple to read, easy to provide, and cross-platform
compatible.
8. Easy to teach – Workload is smaller when compared to other pro-
gramming languages techniques.
9. Easy to use – Python code is faster than other programming languages.
10. Easy to understand – Easier to understand than other programming
languages.
11. Easy to obtain – Python is free, open source, and multiplatform.
1.4 APPLICATIONS OF PYTHON
1. Portable – Python can run on all platforms, like Unix, Windows, and
Macintosh.
2. Extendable – The developer can combine low-level modules to the
Python interpreter. These modules allow the programmers to mod-
ify their tools useful database.
3. Python offers interface to the commercial databases.
4. GUI programming – Python encourages graphical user interface
applications by system calls, libraries, and Windows systems such as
Windows MFC Macintosh and the X Windows system of Unix.
Python Basics ◾ 3
5. Scalable – Python offers systematic structure and assist shell
scripting.
1.5 PYTHON VERSIONS
1. CPython
2. Cython
3. Jython
4. PyPy
5. RPython
1.6 PYTHON IDENTIFIERS
A Python identifier is their name used to recognize a variable, func-
tion, module, class, or an object. An identifier begins with the letter,
or an underscore followed by digits. Python does not permit punctua-
tion marks such as @, $, ^. Python is a case-sensitive programming
language. For example, Test and test are two unique identifiers in
Python.
Naming rules for Python identifiers:
1. Class names begin with an uppercase letter. All additional identifiers
beginning with a lowercase letter.
2. If the identifier closes with two trailing underscores, the identifier is
the language specified special name.
3. Beginning with an identifier with a particular leading _underscore
signifies that the identifier is private.
4. Beginning an identifier with the two prominent underscores indi-
cates it is an intensely private identifier.
1.7 RESERVED WORDS
Table 1.1 shows the Python keywords. These keywords cannot be used as a
constant or variable or any other identifier names.
4 ◾ Learning Professional Python
TABLE 1.1 Reserve Words
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else Is with
except lambda yield
1.8 PRINT () FUNCTION
The print () prints a message onto the screen or to the standard output.
Syntax
print (object, sep=separator, end=end, file= file,
flush=flush)
• sep – Specifies the separator between the outputted argument.
• end – Specifies what to print at the end of the print statement
• flush – Flushes the screen. Its default value is false
• file – Where to display the message object. The default out is to the
console, that is, std.out. The programmers can output the message to
the file also.
The end and sep are the keyword arguments, and these parameters are
used to format the output of the print () function. The programmers can
enter more than one object separated by separator. An empty print () out-
puts an empty line to the screen.
Your first python program:
print (“this is to test”)
The previous line produces the output:
this is to test
Python Basics ◾ 5
If we remove double quotes in the print statement:
print(this is to test)
Output
File “<ipython-input-86-c0dae74495e9>”, line 1
print(this is to test)
^
SyntaxError: invalid syntax
print () can operate with all types of data provided by Python. The data
type data strings, numbers, characters, objects, logical values can be suc-
cessfully passed to print ().
NOTE: print () does not evaluate anything.
Program
print(“this is to test”)
print(“this is the second line in python program”)
Output
this is to test
this is the second line in python program
The preceding program invokes the print () twice. The print () begins
its output from a fresh new line each time it starts its execution. The
output of the code is produced in the same order in which they have
been placed in the source file. The first line in the preceding program
produces the output [this is to test], and the second line produces the
output [this is the second line in python program]. The empty print ()
with without any arguments produces the empty line, that is, just a new
empty line.
Program
print(“this is to test”)
print()
print(“this is the second line in python program”)
6 ◾ Learning Professional Python
Output
this is to test
this is the second line in python program
In the preceding program, the second line print statement introduces
the empty line.
The following programs illustrate the separator and end argument:
Program
print(“this”,“is”,“to”,“test”,end=“@”)
Output
this is to test@
In the preceding program, end separator is used, so after printing the
string, the separator has been added.
Program
print(“this is”,“ to test”,sep=“---”,end=“#”)
print(“this is an experiment”)
Output
this is--- to test#this is an experiment
The string assigned to the end keyword argument can be any length.
The sep arguments value may be an empty string. In the previous exam-
ple, the separator is specified as –. The first and the second argument is
separated by the separator. In the preceding program the separator is –.
So the output is [this is – to test]. In the first the print statement, the end
argument specified is “#”. So after printing the first print statement, the #
symbol is placed, the first line output is [this is – to test#].
Program
print(“this”,“is”,“to”,“test”,end=“\n\n\n”)
print(“this is an experiment”)
Python Basics ◾ 7
Output
this is to test
this is an experiment
In the preceding program, “\n” is used as the end separator, so after
printing the first line string, new lines have been added.
1.9 LINES AND INDENTATION
The Python statement does not end with a semicolon. Python gives no
braces to specify blocks of code for class and function definitions or flow
control. Blocks of code are represented by line indentation. The number
of spaces in the indentation is valuable, and the old statements within the
block must be invented the same indentation. In Python, all the continu-
ous lines are indented with the equivalent number of spaces, which would
form a block. For example:
def test():
a=1
print(a)
The preceding program produces the output 1.
1.10 MULTILINE STATEMENTS
Statements in Python predictably end with the new line. Python per-
mits use of the line continuation character to denote that the line should
continue.
a=test_one+\
test_two+\
test_three
Statements continued with [], {}, () do not need to use the line continu-
ation character, for example:
a= {1,2,3,4,
5,6,7}
8 ◾ Learning Professional Python
1.11 QUOTATION IN PYTHON
Python allows single, double, and triple quotes to signify string literals.
The triple quotes are applied to spend the string within multiple lines. For
example, the following are legal:
S=”test”
S=’test’
S=””” This is to test a multiple lines and sentence “””
1.12 COMMENTS IN PYTHON
A hash sign (#) is the starting of the comment. All characters after the hash
and up to the end of the line are part of the comment, and the Python
interpreter ignores that line. For example:
print (“this is to test”) # Python comment
The Python developer can comment multiple lines as follows:
#This is the first comment
#this is the second line comment
#This is the third line comment
#this is also a comment
Note: Comments omitted at runtime and these comments leave
additional information in code.
Note: The triple quoted string is also ignored by Python in-
terpreter and can be used as a multiline comment.
‘‘‘this is the
test the
multiline comment ’’’’,
Program
print(“test#1”)
print(“test#2”)
#print(“test#3)
Python Basics ◾ 9
Output
test#1
test#2
In the preceding program, the first and the second print statement con-
sists of the # statement in between the quotes, so this # symbol behaves like
a symbol, and the interpreter prints that symbol. But at line 3 the # symbol
is in front of print statement. In this case # symbol works as comment.
Program
#this is
to test comment
print(“python comment”)
Output
File “<ipython-input-28-b77848f8c85d>”, line 2
to test comment
^
SyntaxError: invalid syntax
If we want to display anything at runtime, we must put that content in
quotes inside print statement, otherwise the interpreter throws the error.
In the preceding program, the second line consists of the string without
the print statement. So this line throws the error.
1.13 MULTIPLE STATEMENTS ON A SINGLE LINE
The semicolon (;) lets multiple statements on the single and given that nei-
ther statement starts in new code block. For example:
x=‘test’;print(x)
Output
test
10 ◾ Learning Professional Python
1.14 PYTHON VARIABLES
Every variable has a name and a value. Variables are used to store values
stop. That means when the developer creates a variable, the translator allo-
cates memory and decides what can be saved in the reserved memory. By
allocating different data types of variables, you can store integers, deci-
mals, or characters in these variables.
Syntax
variable name=value
E.g.: i=100
Note: If the programmer assigns any value to a nonexistent variable,
the variable will be automatically created, that is, a variable comes into
existence because of allocating a value to the variable.
1.15 NAMING CONVENTIONS TO VARIABLES
1. The name of the variables must be composed of uppercase or lower-
case alphabets (A . . . Z, a . . . z), digits (0 . . . 9) and the special symbol
underscore (_).
2. The name of the variable must begin with a letter or the special sym-
bol underscore (_) but not with a digit.
3. The name of the variables must be a reserved keyword.
4. Uppercase and lowercase letters are treated as different in Python.
5. Python does not have any restrictions on the length of the variable
name.
6. Some valid variable names are test, sum, test_sum, test1, test1_avg,
myVariable.
7. Some invalid variable names are 5sum, test sum, False, None.
Note: Python is a dynamically typed language; no need to declare
the type of the variable.
Python Basics ◾ 11
1.16 ASSIGNING VALUES TO VARIABLES
Python variables do not require specific declaration to reserve memory
space. The declaration occurs automatically when you allocate a value to
your variable. The = is applied to allocate values to variables. The oper-
ating to the left of the = to operator is the name of the variable and the
operand to the right of the = operator is the value stored in the variable.
For example:
t=100
sname=‘rani’
In the previous example, t and the sname are the variable names and
100 and ‘rani’ are the variable values.
Note: The programmer can assign a new value to the already existing
variable by using either the assignment operator or the shortcut operator.
Program
Test=1
print(test)
Output
--------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-23-f210fd97eab0> in <module>()
1 Test=1
----> 2 print(test)
NameError: name ‘test’ is not defined
Name error has occurred because the variable name is Test but in print
the variable name is test.
Program
i=100
i=50 + 500
print(i)
12 ◾ Learning Professional Python
Output
550
In the previous example, variable i is assigned an integer literal 100, and
in the second line the value of i is reassigned to 550(50 + 500). The variable
retains its latest value, that is, in the second line the old value (i.e., 100) is
overwritten by the value 550(50 + 500).
Program
a=’5’
b=“5”
print(a+b)
Output
55
In the preceding program, the value of a is character literal 5 but not the
numeric value. The value of b is string literal 5. The third line performs the
computation a+b. Here + works as the concatenation operator.
Program: Find the hypotheses of the triangle
a=5.0
b=3.0
c=(a**2+b**2)**0.5
print(“c=”,c)
Output
c= 5.830951894845301
In the preceding program, the ** is the exponentiation operator. In line
3, during expression evaluation, interpreter first computes the expression
a**2+b**2, the higher priority gives to the parenthesis’s operator.
1.17 MULTIPLE ASSIGNMENT
Python allows to allocate a single value to several variables simultane-
ously. For example:
a=b=c=1
Python Basics ◾ 13
In the previous line, the value of a, b, and c is 1.
a, b, c=1,2,3
In the previous example the value a is 1, b is 2, and c is 3.
1.18 NONE VARIABLE
None is a keyword in python, and this word used in circumstances
1. To assign to a variable
E.g., test=None
2. To compare with another variable
if(test==None):
if test is None:
Scope of the variables in Python
1. Global
2. Local
1.19 DATA TYPES
The data stored in memory off many types. Python has various standard
data types, like numbers, strings, list, tuple, dictionary. Number data types
store numeric values, for example Var1= 1.
Python supports four different numeric types:
• int
• long
• float
• complex
14 ◾ Learning Professional Python
1.20 TYPE CONVERSION
Python supports several built-in functions to complete conversion from
one data type to another data type. These functions restore the converted
values. Python supports 2 types of data conversions
1. Implicit conversion
2. Explicit conversion
1.20.1 Implicit Conversion
Python automatically converts one data type to another data type. There is
no need for user involvement.
Program: Implicit Conversion
x=123
y=12.34
print(x+y)
x=123
y=10.0
print(x+y)
x=10 + 1j
y=10.0
print(x+y)
Output
135.34
133.0
(20 + 1j)
Program: Implicit Conversion
x=“test”
y=10
print(x+y)
Output
--------------------------------------------------------------
TypeErrorTraceback
(most recent call last)
Python Basics ◾ 15
<ipython-input-65-d2c36b20b8bd> in <module>()
1 x=“test”
2 y=10
----> 3 print(x+y)
TypeError: can only concatenate str (not “int”) to str
1.20.2 Explicit Conversion
In explicit type conversion, the programmers must use the predefined
functions. This type of conversion is also known as the type casting
because the users are forcing the one data type to another data type by
using predefined functions. The following table gives some predefined
explicit type conversion functions.
TABLE: Conversion Function
Conversion Function Description
int (x [,base]) Converts x to an integer and x is a string
long (x [,base]) Converts x to a long and x is a string
float(x) Converts x to a floating-point number
complex (real [,imag]) Creates a complex number
tuple(x) Converts x to tuple
set(x) Converts x to set
list(x) Converts x to list
dict(d) Creates a dictionary
chr(x) Converts an integer to character
hex(x) Converts an integer to hexadecimal value
oct(x) Converts an integer to octal value
Program
x=“1010”
print(“string=”,x)
print(“conversion to int=”,int(x,2))
print(“conversion to float=”,float(x))
print(“conversion to complex=”,complex(x))
x=10
print(“converting to hexadecimal=”,hex(x))
print(“converting to octal=”,oct(x))
print(“conversion to Ascii=”,chr(x))
x=‘test’
print(“conversion to tuple=”,tuple(x))
print(“conversion to set=”,set(x))
16 ◾ Learning Professional Python
Output
string= 1010
conversion to int= 10
conversion to float= 1010.0
conversion to complex= (1010 + 0j)
converting to hexadecimal= 0xa
converting to octal= 0o12
conversion to Ascii=
conversion to tuple= (‘t’, ‘e’, ‘s’, ‘t’)
conversion to set= {‘s’, ‘t’, ‘e’}
The preceding program uses the explicit data type conversion.
1.21 LITERALS
Literals are nothing but some fixed values in code. Python has various
types of literals – number (e.g., 111 or – 1), float literal (e.g., 2.5 or – 2.5),
string literal (e.g., ‘test’ or “test”), Boolean literal (True/False), None literal.
Note: None literal is used to signify the absence of a value.
Note: Python 3.6 introduced versions of underscores in numeric
literals. For example, 11_11.
Note: Python print () function automatically does the conversion to
the decimal representation from other number systems.
Note: Python omits zero when it is the only digit in front or after
the decimal point.
In Python the number 1 is an integer literal and 1.0 is the float literal.
The programmer has to input the value 1.0 as 1. and 0.1 as .1. To avoid
writing many zeros in, Python uses the scientific notation E or e. For
Python Basics ◾ 17
example, 10000000 can be represented as 1E7 or 1e7. The value before the e
is the base, and the value after the e is the exponent. For example, the float
literal 0.000000001 can be represented as 1e-9 or 1E-9.
1.22 BINARY NUMBER SYSTEM
A binary number system is expressed in zeros and ones.
Program
print(0o13)#octal representation
print(0x13)#hexadecimal representation
Output
11
19
EXERCISE
1. Write the first line of code in the python program using the sep= “$”
and
end= “ . . . ” keywords.
print (“this”, “is”, “to”, ‘test”)
print (“python language”)
2. Write the first line of code in the python program using the sep=
“***” and end= “----” keywords.
print (“this”, “is”, “to”, “test”)
print (“python language”)
3. Write the first line of code in the python program using the sep= “*”
and end= “\n” keywords and second line of code using the sep= “#”
and end= “---”.
print (“this”, “is”, “to”, “test”)
print (“python language”)
18 ◾ Learning Professional Python
4. Check the following code:
print (true>false)
print (true<false)
5. What is the decimal value for the binary number 1101?
6. What is the decimal value for the binary number 1001?
7. What is the hexadecimal value for the binary number 1101?
8. What is the octal value for the binary number 1101?
9. What is the octal value for the decimal number 145?
10. What is the hexadecimal value for the decimal number 123?
Chapter 2
Python Operators
2.1 OPERATORS INTRODUCTION
An operator is a symbol that can operate on the operands. The operators
can be classified as follows:
1. Unary Operator
2. Binary Operator
3. Ternary Operator
2.1.1 Unary Operators
It works on single variable. The unary operators in python are the following:
+, -,
2.1.2 Binary Operator
It works on single variables. For binary operators, refer to section 2.2.
2.1.3 Ternary Operator
It works on three variables. Ternary operator evaluates the expression
based on the condition being true or false. Ternary operator allows the
testing condition in a single line instead of the multiline if else code.
DOI: 10.1201/9781003414322-2 19
20 ◾ Learning Professional Python
a,b = 10, 20
print(a if a> b else b)
Output
20
2.2 BINARY OPERATORS
Python language supports the seven types of binary operators:
1. Arithmetic Operators
2. Relational Operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
2.2.1 Arithmetic Operators
TABLE Arithmetic Operators
S.No Operator Name Example Program Result
1 + addition a+b a,b=l,4 5
print(a+b)
2 - subtraction a-b a,b=l0,5 5
print(a-b)
3 * multiplication a*b a,b=l0,5 50
print(a*b)
4 / division a/b a,b=10,3 3.3333333333333335
print(a/b)
5 % modulus a%b a,b=l0,3 1
print(a%b)
6 ** exponentiation a**b a,b=10,5 100000
print(a**b)
7 // floor division a//b a,b=10,3 3
print(a//b)
Python Operators ◾ 21
Program
The preceding program is about Python program to perform arithmetic
operations.
Note: For **(exponentiation) operator the left argument is the base,
and the right argument is the exponent (baseexponent e.g.: 2**3 = 23=8).
Note: When using **, if both operands are integers, then the result
is an integer.
Note: When using **, if one of the operands is float, then the result
is a float.
Note: The result produced by the division operator is always a float
value.
Note: For integer divisional operator (//), the result is always
rounded towards the lesser integer value.
22 ◾ Learning Professional Python
Note: When using //, if both operands are integers, then the result
is an integer.
Note: When using //, if one of the operands is float, then the result
is a float.
2.2.2 Shortened Operators
TABLE Assignment Operators (Screenshot)
S.No Operator Name Example Program Result
1 = assignment a=b a,b= 10,5
2 += add and a+=b a,b=10,5 15
a+=b
print(a)
3 -= subtract and a-=b a,b=10,5 5
a-=b
print(a)
4 *= multiply and a*=b a,b=10,5 50
a*=b
print(a)
5 /= divide and a/=b a,b=10,5 2.0
a/=b
print(a)
6 %= modulus and a%=b a,b=10,5 0
a%=b
print(a)
7 //= floor division a//=b a,b=10,5 2
and a//=b
print(a)
8 **= exponent and a**=b a,b=10,5 100000
a**=b
print(a)
9 &= bitwise and a&=b a,b=10,5 0
a&=b
print(a)
(Continued)
Python Operators ◾ 23
TABLE (Continued) Assignment Operators (Screenshot)
S.No Operator Name Example Program Result
10 |= bitwise or and a|=b a,b=10,5 15
a|=b
print(a)
11 ^= bitwise xor and a^=b a,b=10,5 15
a^=b
print(a)
12 >>= binary rght shift a>>=b a,b=10,5 0
and a>>=b
print(a)
13 <<= binary left shift a<<=b a,b=10,5 320
and a<<=b
print(a)
Program
The preceding program is about Python program to perform assignment
operations.
24 ◾ Learning Professional Python
TABLE Comparison Operators
S.No Operator Name Syntax Program Result
1 == equal to a==b a,b=10,5 False
print(a==b)
2 != not equal to a!=b a,b=10,5 True
print(a!=b)
3 < less than a<b a,b=10,5 False
print(a<b)
4 <= less than equal to a<=b a,b=10,5 False
print(a<=b)
5 > greater than a>b a,b=10,5 True
print(a>b)
6 >= greater than equal to a>=b a,b=10,5 True
print(a>=b)
Program
The preceding program is about Python program to perform relational
operations.
TABLE Logical Operators
S.No Operator Name Example Program Result
1 and logical and a and b a,b=10,5 5
print(a and b)
2 or logical or a or b a,b=10,5 10
print(a or b)
3 not logical not not a a False
print(not a)
Python Operators ◾ 25
Program
The preceding program is about Python program to perform logical
operations.
TABLE Identity Operators
S.No Operator Example Program Result
1 is a is b a,b=10,5 False
print(a is b)
2 is not a is not b a,b=10,5 True
print(a is not b)
TABLE Membership Operators
S.No Operator Example Program Result
1 in 10 in list l=[10,20] True
print(10 in l)
2 not in 10 not in list print(10 not False
in l)
TABLE Bitwise Operators
S. No Operator Name Example Program Result
1 & bitwise and a&b a,b=10,5 0
print(a&b)
2 | bitwise or a|b a,b=10,5 15
print(a|b)
(Continued)
26 ◾ Learning Professional Python
TABLE (Continued) Bitwise Operators
S. No Operator Name Example Program Result
3 ~ bitwise not ã a,b=10,5 -6
print(~b)
4 ^ bitwise xor a^b a,b=10,5 15
print(a^b)
5 >> bitwise right a>>b a,b=10,5 0
shift print(a”b)
6 << bitwise left a<<b a,b=10,5 320
shift print(a<<b)
Program
The preceding program is about Python program to perform bitwise
operations.
2.3 STRING OPERATORS
The string operators in Python are + (concatenation) and * (replication).
Concatenation operator concatenates more than one string into one. The
concatenation operator is not commutative, for example, ab is not equal to
ba. When * sign is applied to string and a number, it replicates the string
the same number of times specified by the number.
Python Operators ◾ 27
Syntax of replication operator:
• String*number
• Number*string
Program: Concatenation operator
s=”test”
s1=”ing”
print(s+s1)
Output
testing
Program: Replication operator
print(“test”*3)
print(3*“sample”)
print (3*”1”)#outputs 111 but not 3
Output
testtesttest
samplesamplesample
111
2.4 OPERATOR PRECEDENCE
When more than one operator is there in the expression, to compute the
expression operator precedence determines which operation to perform
first. Operator associativity evaluates the operators in particular order
when the operators have the same precedence.
TABLE Operator Priority
Priority Operator Description
1 +- Unary
2 ** Binary
3 / // % * Binary
4 +- Binary
5 <<= >>= Binary
6 ==!= Binary
28 ◾ Learning Professional Python
TABLE Operator Precedence and Associativity
Operator Precedence Order Meaning Associativity
() Parentheses left-to-right
** Exponent right-to-left
+,-,~ Unary addition, Unary subtraction, left-to-right
and unary bitwise not
*, /, //, % Multiplication, division, floor left-to-right
division, modulus
+, - Addition, subtraction left-to-right
<<, >> Bitwise shift operators left-to-right
?
& Bitwise and left-to-right
^ Bitwise xor left-to-right
| Bitwise or left-to-right
==, !=, >, >=, <, <=, is, is not, in, Comparison, identity, and left-to-right
not in membership operators
and, or Logical and, logical or left-to-right
not Logical not right-to-left
=, +=, - Assignment operators right-to-left
=, *=, /=, %=, &=, ^=, |=, >>=,
<<=
2.5 EXPRESSION EVALUATION
An expression is a combination of operands and operators. In Python,
eval () evaluates the expression dynamically.
Syntax:
eval(expression[,globals[,locals]])
E.g.: eval(“123 + 123”)
246
E.g.: eval(“sum[10,10,10])”,{})
30
E.g.: x=100,y=100
eval(“x+y”)
200
In the given example both x and y are global
variables.
E.g.: eval(“x+50”,{},{“x”:50})
100
In the cited example x is the local variable because it is defined inside
the eval function.
Python Operators ◾ 29
2.6 INPUT () FUNCTION
The input () function can read the data entered by the programmer. The
input () prompts the programmer to input some data from the console
(default from keyboard). When the input () function is invoked without
arguments, the function will switch the console to the input mode. The
cursor blinks, and the programmer can input some keys. By pressing the
enter key, the inputted data will be sent to the source code through
the input functions result. The programmers must catch what the input
function returns otherwise the entered data will be lost.
Note: The default return type of the input () function is the string.
Note: The input () function is invoked with one argument.
E.g.: i=input ()
Program
print(“enter 2 integers”)
a=int(input())
b=int(input())
print(a+b)
Output
enter 2 integers
10
30
40
The preceding program uses the input () function without arguments.
Program
a=int(input(“enter integer:”))
b=int(input(“enter integer:”))
c=a+b
print(“sum=”,c)
Output
enter integer:1
enter integer:3
sum= 4
30 ◾ Learning Professional Python
The preceding program uses the input () function with arguments.
Program
a=input()
print(a+3)
Output
5
--------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-3ae605921ae5> in <module>()
1 a=input()
----> 2 print(a+3)
TypeError: can only concatenate str (not “int”) to str
In the preceding program it’s a type error because the input returns
string data type. Python does not concatenate the string and the integer.
So the previous program throws the type error.
Program
a=input()
print(type(a))
Output
4
<class ‘str’>
In the preceding program, the entered value is 10. Though the value 10
is an integer, the default return type value of the input () function is the
string, so the output of the print function is the str (string).
Program
a=float(input(“enter float value”))
b=float(input(“enter float value”))
c=a+b
print(“sum of floats=”,c)
Python Operators ◾ 31
Output
enter float value1.5
enter float value3.8
sum of floats= 5.3
The preceding program performed sum of two floats. To convert the
input value to float, there is a need to typecast the input () function with
float.
Program
n=int(input(“enter integer”))
print(n*“1”)
Output
enter integer4
1111
The program is about replication operation by reading data from the
user.
Program
#Ascii value
x=input(“enter character:”)
print(“Ascii of ”,x,“is”,ord(x))
Output
enter character:a
Ascii of a is 97
The preceding program prints ascii value.
Program
print(“%5.3e”% (123.456789))
print(“%10.3e”% (123.456789))
print(“%15.3e”% (123.456789))
print(“%-15.3e”% (123.456789))
print(“%5.3E”% (123.456789))
32 ◾ Learning Professional Python
print(“%o”% (15))
print(“%5.3o”% (15))
print(“%x”% (15))
print(“%X”% (15))
print(“%10x”% (15))
print(“%10.3x”% (15))
print(“%x%%”% (15))
print(“%d”% (123456789))
print(“%d,”% (123456789))
print(“{0:4,d}”.format(123456789))
print(“{0:06d}”.format(123))
print(“{0:4,.5f}”.format(123456789.123456789))
Output:
1.235e+02
1.235e+02
1.235e+02
1.235e+02
1.235E+02
17
017
f
F
f
00f
f%
123456789
123456789,
123,456,789
000123
123,456,789.12346
The preceding program is about formatting the numbers.
Program
print(“this book costs {0:f} only”.format(150.99))
print(“this book costs {0:8f} only”.format(150.99))
print(“this book costs {0:.2f} only”.format(150.99))
print(“this book costs {0:.3f} only”.format(150.99))
print(“this book costs {0:.0f} only”.format(150.99))
print(“this book costs {0:e} only”.format(150.99))
Python Operators ◾ 33
print(“this book costs {0:1} only”.format(150.99))
print(“this book costs {0:d} only”.format(150))
print(“this book costs {0:8d} only”.format(150))
print(“this book costs {0:o} only”.format(150))#octal
print(“this book costs {0:b} only”.format(150))#binary
print(“{:d}”.format(-15))
print(“{:=7d}”.format(-15))
print(“{:=7d}”.format(15))
Output
this book costs 150.990000 only
this book costs 150.990000 only
this book costs 150.99 only
this book costs 150.990 only
this book costs 151 only
this book costs 1.509900e+02 only
this book costs 150.99 only
this book costs 150 only
this book costs 150 only
this book costs 226 only
this book costs 10010110 only
– 15
– 15
15
The preceding program is about formatting the numbers.
2.7 LIBRARIES
2.7.1 Math and CMath Libraries
Math is the basic math module that deals with mathematical operations
like sum, mean, exponential, etc., and this library is not useful with com-
plex mathematical operations like matrix multiplication. The disadvan-
tage is the mathematical operations performed with the math library are
very slow. For instance, if we consider the example shown here, we per-
formed the basic mathematical operations. The statement math.exp is used
to find the exponent of the number. For example, math.exp (5) means e to
the power of 5, that is, e5. The value of e is approximately 2.17. The state-
ment math.pi returns the value approximately 3.14. The constant math.e
returns the value 2.17. The ceil returns the ceiling value not greater than
34 ◾ Learning Professional Python
that number. The floor returns the floor value of the given number. The
math.trunc method returns the truncated part of the number.
TABLE Math Functions
Function Description
min (x1, x2 . . .) The smallest of all its arguments
max (x1, x2 . . .) The largest of all its arguments
pow (x, y) The value of x**y, i.e. (2**3 = 8) (23=8)
round (x [, n]) X rounded to n digits from the decimal point
sqrt(x) The square root of x
abs(x) The absolute value of x
ceil(x) The smallest integer not less than x
floor(x) The largest integer not greater than x
exp(x) The exponent of x (ex)
log(x) The natural logarithm of x
Iog10(x) The base 10 logarithm of x
fabs((x) The absolute value of x
Program
import math
x,y,z=10,20,30
print(“min=”,min(x,y,z))
print(“max=”,max(x,y,z))
print(“sqrt of ”,x,“=”,math.sqrt(x))
print(“round=”,round(0.5))
print(“power=”,pow(2,3))
f=1.5
print(“ceil=”,math.ceil(f))
print(“floor=”,math.floor(f))
x=2
print(“exponent=”,math.exp(x))
print(“log=”,math.log(x))
print(“log10=”,math.log10(x))
x=-1
print(“absolute=”,abs(x))
print(“absolute=”,math.fabs(x))
Output
min= 10
max= 30
Python Operators ◾ 35
sqrt of 10 = 3.1622776601683795
round= 0
power= 8
ceil= 2
floor= 1
exponent= 7.38905609893065
log= 0.6931471805599453
log10= 0.3010299956639812
absolute= 1
absolute= 1.0
The preceding example uses some math operations and produces the
output based on the mathematical operation used.
import math
print(“exp(5)”,math.exp(5))
print(“Pi”,math.pi)
print(“Exponent”,math.e)
print(“factorial(5)”,math.factorial(5))
print(“ceil(-5)”,math.ceil(-5))
print(“ceil(5)”,math.ceil(5))
print(“ceil(5.8)”,math.ceil(5.8))
print(“floor(-5)”,math.floor(-5))
print(“floor(5)”,math.floor(5))
print(“floor(5.8)”,math.floor(5.8))
print(“trunc(-5.43)”,math.trunc(-5.43))
print(“pow(3,4)”,math.pow(3,4))
print(“pow(3,4.5)”,math. pow(3,4.5))
print(“pow(math.pi,4)”,math. pow(math.pi,4))
print(“log(4)”,math.log(4))
print(“log(3,4)”,math.log(3,4))
print(“log(math.pi,4)”,math.log(math.pi,4))
print(“sqrt(8)”,math.sqrt(8))
Similarly the mathematical operations for complex numbers can be
obtained by the CMath module in Python. The methods in CMath always
returns a complex number. If the return value can be expressed as a real
number, then the return value for the imaginary is zero. The command
lines perform the mathematical operations on the complex numbers.
import cmath
print(“cmath.pi”,cmath.pi)
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Bangerter's
Inventions; His Marvelous Time Clock
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Title: Bangerter's Inventions; His Marvelous Time Clock
Editor: Everett Lincoln King
Release date: May 25, 2016 [eBook #52161]
Most recently updated: October 23, 2024
Language: English
Credits: Produced by Chris Curnow, Chuck Greif and the Online
Distributed Proofreading Team at http://www.pgdp.net
(This
file was produced from images generously made available
by The Internet Archive)
*** START OF THE PROJECT GUTENBERG EBOOK BANGERTER'S
INVENTIONS; HIS MARVELOUS TIME CLOCK ***
Contents.
(In certain versions of this etext [in
certain browsers] clicking directly
on the image, will bring up a larger
version of the illustration.)
(etext transcriber's note)
Young His
Wonderful
Swiss Time Clock
an
Inventor’s Eloquent
Solution
Most of
Motion
Marvelous and
Perpetual
Achieve- Force
ment
FRIEDRICH BANGERTER
Inventor
Copyright, 1911, by
FRIEDRICH BANGERTER,
50 Church Street,
New York.
GOLD AND SILVER MEDALS AND DIPLOMAS
At the World Universal Expositions in Paris, 1900, and in Belgium,
1905, for Bangerter’s Many Marvelous Inventions.
BANGERTER’S
INVENTIONS
=====HIS=====
MARVELOUS
TIME CLOCK
=============
EDITED BY KING
CONTENTS
Page
DREAM OF AGES REALIZED 9
Perpetual Force 9
A Practical Invention 10
A Truly Wonderful Invention 10
What Does Perpetual Motion Mean? 13
Napoleon’s Fatal Error 13
Flying Machines Everywhere 14
America! Land of Opportunities 17
Stimulus to Inventive Genius 17
Perpetual Motion, the Study of Ages 18
When Nature Is Ready 18
Other Natural Forces 21
Variation of Temperature 21
Nature’s Many Phenomena 22
Nature’s Great Planetary Clockwork 22
Heat the Source of All Power 25
Heat—Expansion and Contraction 25
SPECIFICATION 29
BANGERTER’S ANNIVERSARY SELF-WINDING REGULATOR 73
BANGERTER’S FIRE DETECTOR AND FIRE ALARM 77
BANGERTER’S FIRE ALARM AND WATER SPRINKLER 79
BRIEF BIOGRAPHY OF FRIEDRICH BANGERTER 81
BANGERTER’S AUTOMATIC WATCH CHAIN MACHINE 83
BANGERTER’S WRITING AND TALKING DOLL 87
BANGERTER’S AUTOMATIC JEWELER 91
BANGERTER’S AIRSHIP 93
BANGERTER’S POWDERLESS GUN 95
DREAM OF AGES REALIZED
HE Twentieth Century is the century of successful
accomplishment. The zenith of human achievements appears to
have been reached. Yet every day brings its new surprises.
There seems to be no limit to the output of human genius and
ingenuity. We have now the aeroplane skimming through the
air with bird-like ease and rapidity; the wireless telegraph and wireless
telephone; the leviathan steamship “Olympic,” which annihilates distance
between Europe and America and a sight of which would make our
ancestors gasp in amazement, as well as other modern marvels.
And these pages tell about one of the greatest inventions of all time—a
discovery of to-day that will add a crowning glory to successful Twentieth
Century endeavor.
Bangerter’s Perpetulium Time Clock is most concrete, tangible and
eloquent evidence that PERPETUAL FORCE—the greatest of all
mechanical problems—is solved at last.
PERPETUAL FORCE!
Bangerter’s latest and highly successful creation sounds like a fairy story
realized. The wizardry of true genius is thus marvellously expressed.
Volumes have been written by prominent authors and leading scientific men
illustrating the wasted efforts and picturing the despair of many inventors in
all ages who failed in their persistent efforts to solve the problem of
perpetual force—producing motion. Centuries of unwearying studies and
activities only met with failure. It was called an impossible task, a phantom,
a phantasy, a freak of the imagination that never could be converted to a
practical issue.
But the failure of those who attempted and failed in the past could not
keep back the energy and force of progress.
To-day the problem of perpetual force is really solved. It remained for a
young Swiss inventor—Mr. Friedrich Bangerter—to successfully
accomplish the heretofore impossible.
Bangerter’s Perpetual Time Clock is perfect in theory and practice. It is
operated by a principle that cannot fail. A glance at the machine will
convince the most skeptical.
From time to time we read of wonderful inventions that never get
beyond the stage where they are talked about. They are impractical and
impossible, because their inventors are fakirs, fanatics or dreamers—
inventors lacking the character, knowledge and brains to understand
whether or not their ideas are of any realizable value.
A PRACTICAL INVENTION
This is emphatically not the case with Mr. Bangerter. His is a most
practical mind. His record as an inventor is one of successes. He has had
twenty years’ experience as a practical and technical mechanical engineer,
with a great number of patents and inventions in operation all over the
world. His marvelous automatic machines—taking wrought casting and
bars of metal and automatically making gears, chains, spindles, screws,
pinions, etc., of the highest precision—is a striking example of his great
ability.
At two World’s Expositions—in Paris, 1900, and Belgium, 1905—the
Jury of International Selection of Mechanical Experts awarded him Silver
and Gold Medals and Diplomas for his inventions of the most marvelous
machines.
A TRULY WONDERFUL INVENTION
Bangerter’s Perpetual Time Clock is a truly wonderful mechanism and
an exact, reliable timepiece. It will do the work for which it is intended, as
long as the mechanical parts hold together—as long as the shafts and
spindles run in their bearings.
In other words, this clock will run for
BANGERTER’S
PERPETUAL
CLOCK.
generations—yes, from 100 to 500 years—without winding. During this
unbelievably long period this clock will run, show the exact time, strike the
hours and play the marvelous Westminster melodies without the slightest
expenditure of time or effort in winding up with springs or weights.
There is employed no electricity, chemicals, secret preparations or fuel,
to produce the power and energy to run Bangerter’s Perpetual Force Clock.
Yet there is a natural law behind it all—the secret of its practical application
was discovered and successfully applied by the young Swiss inventor.
WHAT DOES PERPETUAL MOTION MEAN?
To avoid loss of time and to obviate dissension and discussion between
readers and critics herewith is given the technical understanding of the title
“PERPETUAL MOTION.” It is taken from “The International Cyclopedia,”
Vol. II, Page 522, and reads as follows:
“Perpetual Motion means an engine which, without any supply of power
from without, can not only maintain its own motion forever, or as long as its
material lasts, but can also be applied to drive machinery, and therefore to
do external work. In other words, it means a device for creating power
energy without corresponding expenditure. This is now known to be
absolutely impossible, no matter what physical forces be employed.”
The Bangerter Clock is eloquent evidence that the theory just quoted
(and heretofore generally accepted as correct) is not, in fact, correct. It will
be necessary, in the face of this new discovery, to write a new definition of
Perpetual Motion.
Impossibilities of yesterday are the stern realities of to-day. We have
now arrived at such a stage of advancement as to be surprised at no
discovery or invention, no matter how improbable or wonderful.
NAPOLEON’S FATAL ERROR.
Napoleon was advised not to listen to Fulton’s plan of the steamboat—a
certain cause of his downfall, for had he accepted Fulton’s radical and
previously unheard of ideas he would presently have a fleet of steamships.
He would thus be Emperor of the Ocean, for with his fleet of steamships he
would surely have conquered Britain’s old-fashioned sailing navy.
Ten years ago all the scientific men to whom Bangerter presented his
plans for an airship, gravely shook their heads. They said:—
“Your principle is right—it shows the most practical device we have yet
seen, and if there were such proposition as a ‘heavier-than-air’ possibility
you would have the best chance of success.”
Very well, the “heavier-than-air” possibility has become a certainty. To-
day scientific men see the weight of a man’s body (increased by a heavy
framework and many mechanical contrivances) soar lightly and
majestically between the blue sky and the earth below. The dream of the
pitied and sneered at inventor of a decade ago is exemplified to-day all over
the civilized world!
All this the scientists a few years ago did not see.
The new born force—insignificant in size and appearance, but giant-like
in actual force—now known as the gasolene engine, did not then make an
appearance. But now hundreds of machines are flying all over the world—
propelled by the pygmy gasolene engine.
In other words, as the force of a man is mechanically figured to 1-7 of
one H. P., some gasolene engines of the weight and size of a man develop
700 times more power.
This enormous force may soon bring about a revolution in warfare by
displacing powder as a force to expel bullets from guns.
Tests made last year with a small model gun have demonstrated great
possibilities by shooting small 3-8 inch round ball-bearing at so terrific a
speed that they pierced a 1½-inch pine target at 60 feet distance, and in such
enormous quantities that inside of a few seconds five targets were riddled to
atoms.
FLYING MACHINES EVERYWHERE.
Aeroplanes are to-day counted by hundreds. Some carry ten or more
men at a time, and keeping it up for hours with a speed of nearly 100 miles
per hour.
How great is the number of the wonderful time-saving, effort-saving and
distance-annihilating inventions of the past fifty years!
BANGERTER’S
PERPETUAL
CLOCK.
How wonderful is the transformation! How sudden and how amazingly
great is the progress that a single generation produces in this remarkable
century! Great men have lived before us. Intellectual giants were our fathers
and grandfathers. But the time had not come for the infinite hand to touch
the mainspring that would set all these fountains of activity to pouring out
their rich treasures of knowledge and invention. But as soon as the time is
reached, how supremely marvelous are the undreamed-of achievements!
AMERICA! LAND OF OPPORTUNITIES.
The development of the greatest of all countries—the United States of
America—is a most prolific source and cause of inventions. After the Civil
War had proven that equality and freedom were not mere figures of speech,
but that they were real, substantial blessings to be enjoyed by all American
citizens, a great stimulus to inventive genius was given. The brains
responded to the call for improvement and development.
The winnings from mining, the rewards from manufacture, the profits to
be derived in the thousand and one forms of commerce and the handsome
payments to be derived from agriculture, lumbering, cattle raising, fruit
culture, etc., were the strongest possible incentives to the exercise of brains
and inventive ingenuity.
Manufacture and commerce were fostered and developed by rapid
transportation. Railroads and steamships soon ran wherever needed.
Prosperity and happiness were the natural results of this wholesale national
activity.
The machinery of warfare, such as marine fortifications, great guns and
war vessels, was installed and maintained at an enormous expense.
It is not too much to say that America’s prosperity has aroused the
greatest possible interest in European countries. They have made the most
strenuous exertions in order to compete in the world’s trade marts.
STIMULUS TO INVENTIVE GENIUS.
A long period of universal peace has made it possible to keep up
inventive investigation and experimenting with marvelously fruitful results.
Up to the present time more than ONE MILLION PATENTS have been
issued for the United States alone. Truly a marvelous record!
PERPETUAL MOTION—THE STUDY OF AGES.
In every age inventors have dreamed of that problem of problems—
Perpetual Motion. It is a problem that has exhausted the mind, purse and
patience of thousands of inventors. Almost every one has heard of some one
else’s interest in this great subject. But history shows that the study of
perpetual motion has been tinctured with charlatanism.
Fakirs have from time to time shown contrivances which seemed to
solve the problem, but were delusions and humbugs pure and simple, as
they were gotten up to delude the public and deceive investors. The
notorious Keely Motor was but one case of many.
Notwithstanding the enormous amount of unsuccessful effort and study
in an endeavor to solve Perpetual Motion there are yet many enthusiastic
students earnestly laboring in the field.
There is one great Perpetual Motion. It is Nature’s own handiwork, and
the only successful human attempt is exemplified in Bangerter’s
marvelously combined clockwork in which the silent forces of Nature are
harnessed to carry out immutable laws. Similar attempts had already been
undertaken by scientific men, but without success, until Friedrich Bangerter
touched the true keynote.
WHEN NATURE IS READY.
The time and conditions were ripe and ready. So was the man! It seems
to be one of the great laws of Mother Nature to withhold her most precious
secrets until she sees fit to divulge them, and then she brings in happy
juxtaposition “The Time, The Place and The Man.”
This has proven true with most of the world’s most important inventions
and discoveries. Nature in her own good time gives up the priceless secret
—that little something that spells success and that was so long sought after
until the golden moment it was revealed.
BANGERTER’S PERPETUAL CLOCK.
Had Lilienthal to-day’s gasolene engine—an engine developing 100 H.
P. to the weight of only 200 pounds, as the rotary Gnome Engine, he would
have been highly successful in his efforts to fly.
The development of the automobile meant the development of the
gasolene engine, which became so reduced in weight and so powerful in
action that all that was necessary was to attach it to some planes, revolve
propellers, and, presto! off went the flying machine with ease and speed.
As time goes on and as the needs of men multiply other great inventions
will be perfected in obedience to the universal Law of Creation.
Every student of Perpetual Motion, yes, every intelligent observer of the
world’s progress, will be intensely interested in Bangerter’s wonderful
clock.
OTHER NATURAL FORCES.
There are many other natural sources that could be called in to develop
Perpetual Force for clocks, machinery, etc., just as waterfalls, rainfalls, the
blowing of winds, etc., but all these could not be considered and compared
with Bangerter’s inventions. They are at present impractical on account of
the extensive and expensive outside connections required.
Streams are sometimes found only at great distances, and the entire
system of turbines, dynamos, electrical conducting wires and motors are
much too complicated to operate a simple system of your own.
VARIATION OF TEMPERATURE.
We cannot depend upon a wind or a rainfall, but we can always depend
upon a variation of temperature day after day and year after year. Some
days there may be a variation of only one or two degrees, other days from
15 to 25 degrees, but no matter what the variation may be, Bangerter’s
machine collects the daily results and stores their energies.
These results are produced day after day by the phenomena of expansion
and contraction of material, and is so combined as to always have sufficient
force stored to always keep the clock running.
In other words, Bangerter’s Perpetulium Time Clock will always run
without winding.
Even if there should be no variation of temperature for a period of
several days or weeks—which will never happen as long as the world exists
—sufficient force would be stored from past variations to keep it running
for a considerable period of time.
This clock will give perfect time in any room, in any house or building
and in any exterior or interior location. It is not affected by time or locality.
The mysterious forces of Nature operate it equally as well in the jungles of
Africa as in a New York or London mansion.
It is the one clock for all time, all localities and all conditions.
NATURE’S MANY PHENOMENA.
How marvelous and manifold are the workings of Nature! Her
phenomena and secrets are ever subjects of intense study by the world’s
greatest intellects.
Nature’s manifestations are mild, majestic, mighty, cold, calm,
bounteous, benign, beneficent, beautiful, terrific, tender, temperate—in fact,
every adjective in the English language could be employed to describe her
full gamut of moods.
Some of us have heard the furious roaring of a blizzard and observed the
enormous force and terrific speed of the tempest, leaving behind death and
destruction in its wake. Many towns, large and small, have been swept out
of existence by blizzards, tornadoes and cyclones.
And the silent, fructifying forces of Nature—how grand and beautiful
beyond expression do they accomplish their work! “Great oaks from little
acorns grow,” and from little, apparently insignificant seeds spring monarch
trees of the forest, their crowns majestically waving three and four hundred
feet in the air. The mysteries of life have yet been revealed to no man, and
the artist has not lived who has been able to paint the picture, to catch the
true color effects, that only Mother Nature can depict on a world wide
canvas.
NATURE’S GREAT PLANETARY CLOCKWORK.
Every atom of force in the universe performs a purpose and function.
Nature never makes a mistake.
BANGERTER’S
PERPETUAL
CLOCK.
Each of the myriad forces under her control has the most logical cause
for existence, and all are under the guidance of the most perfect system. The
entire planetary system may be termed the Clockwork of the Universe—the
great Natural Clock, absolutely authoritative and perfect in operation and
giving us days, nights, seasons and variations of temperature with a
regularity that never fails.
These variations of temperature really mean the source of all life and
vegetation. In order that we human beings live the globe must revolve on its
axis, and as the year grows on apace we receive the heat rays from another
planet—the Sun—in different angles and positions and in the variations of
temperature ranging from extreme heat to extreme cold.
HEAT THE SOURCE OF ALL POWER.
From heat comes all power. When the latent forces of Nature were first
set aflame by primitive man he touched the spring of civilization. Since that
time fire has been working for human progress. It is one of the most
powerful agents in the development of civilization.
Our rude ancestors long ago discovered its great utility, and they
cudgeled their brains to aid the flame of fire and obtain a still fiercer heat.
The bellows was the result—the wind pointed the way to this invention.
Then followed by slow degrees the acquirement of further knowledge
concerning fire and its uses. Our forefathers learned the processes of
melting and smelting—later were established various metallurgical
operations.
The path was thus prepared for Tubal Cain and other artificers in metals.
Man eventually became exceedingly skilled in applying heat forces in his
many requirements in articles of brass, tin, zinc, steel, etc.
HEAT—EXPANSION AND CONTRACTION.
From an article by J. Gordon Ogden, Ph.D., in “Popular Mechanics,”
September, 1910, we quote:
“Expansion is one of the most remarkable of the phenomena to be
reckoned with in the natural world. Practically every bit of matter from the
Great Brooklyn Bridge to the tiny hairspring in one’s watch is under its
imperial domination. It is a tremendous force, and the world of mechanics
has to treat it with the deference and respect due to its gigantic power.
Unlike gravity, and other forces of nature, it is whimsical and takes sudden
fits and starts, now acting one way, now another. It affects different bodies
in different ways, and seems to be at variance with the time-honored forces
whose action can be predicted under all circumstances. At least that is what
it apparently does. In our meagre knowledge of the great underlying laws
that control the universe it is possibly unwise to speak so unkindly of
expansion, as though it were a spoiled child in need of correction; its
behavior, however, is so contrary to what one might expect that one is at a
loss to say anything else.
“The walls of a building are sometimes rectified by the enormous force
exerted by the contraction of iron rods. Bars of iron are placed so as to join
the two walls where the bulging is most pronounced. These bars terminate
in screws furnished with nuts. The whole of their length is heated and the
nuts tightened. On cooling the bars will contract with practically irresistible
force, causing the walls to straighten up. This operation is repeated until the
rectification is completed. Boiler plates are fastened with red-hot rivets. The
contraction of the rivets incident upon their cooling draws the plates tightly
together, forming a steam-proof joint.”
“Tyndall, in his work on heat, gives an excellent illustration of the force
of expansion and contraction. ‘The choir of Bristol Cathedral was covered
with sheet lead, the length of the covering being 60 feet and its depth 19
feet 5 inches. It had been laid in the year 1851, and two years afterward it
had moved bodily down for a distance of 18 inches. The descent had been
continually going on from the time the lead had been laid down, and an
attempt to stop it by driving nails into the rafters had failed, for the force
with which the lead had descended was sufficient to draw out the nails. The
roof was not a steep one, and the lead could have rested on it forever
without sliding down by gravity. What, then, was the cause of the descent?
The lead was exposed to the varying temperatures of day and night. During
the day the heat imparted to it caused it to expand. Had it lain upon a
horizontal surface, it would have expanded all around; but as it lay upon an
inclined surface it expanded more freely downward than upward. When, on
the contrary, the lead contracted at night its upper edge was drawn more
easily downward than its lower edge upward. Its motion was, therefore,
exactly like that of a common earthworm; it pushed its lower edge forward
during the day and drew its upper edge after it during the night, and thus by
degrees it crawled through a space of 18 inches in two years.’
“Mention has been made in a preceding article of the effect of unequal
expansion upon two different metals that have been bolted together. It is by
this principle that the action of the ordinary thermostat, so familiar now as a
controller and regulator of the temperature of high buildings, is explained—
a rod made up of two different metals whose rates of expansion are
different. When the temperature of the room in which the thermostat is
placed becomes too high the rod curls toward the metal point S and touches
it, completing an electrical contact which causes a motor to shut off the
draft. When the temperature of the room falls below a certain point the rod
curls in the opposite direction toward the metal point T. This causes a motor
to open the draft and thus furnish a more abundant supply of hot air.
“Everybody in these days of cheap and reliable timepieces carries a
watch. And yet there are very few who appreciate the methods and devices
by means of which the troublesome expansion and contraction of metals are
corrected, in order that a watch may keep correct time. The balance wheel
of a watch corresponds to the pendulum of a clock, and any variation in its
dimensions will cause it to move faster or slower, as the case may be. The
hairspring is really a long strip of metal which becomes weakened in its
effect when expanded by an increase in temperature and has its power
augmented when contraction takes place.
“To correct both of these conditions the rim of the balance wheel is made
up of two different metals, the outer part brass, the inner part iron. When
the hairspring becomes weaker by expansion the brass of the balance wheel
also expands; but as it expands more than the iron to which it is bonded, it
curls in toward the center of the wheel, making practically a wheel of
smaller diameter, and causing the same effect as is produced when a clock
pendulum is shortened. Exactly the opposite conditions obtain when the
timepiece is exposed to extreme cold and the balance wheel has its diameter
increased, thus causing a slowing up to counteract the increased strain
produced by the contraction of the hairspring. The same principle is applied
in the construction of first-class clocks. Any uncorrected variation in the
length of a pendulum is fatal to the timekeeping quality of a clock. A
gridiron pendulum made up of alternate rods of steel and brass serves to
correct the result of the expansive force.
“The central steel rod passes through holes in the lower horizontal
framework and supports the bob at the lower end. The steel rods are so
arranged that they will expand downward, while the brass rods expand
upward and the total length of each metal used is exactly sufficient to
counteract each other’s expansion, and the centre of the bob will remain at a
constant distance from the point of suspension.”
Scientific men and engineers are more or less familiar with the
phenomena of expansion. But no inventor produced a system capable of
utilizing this force to run a clock until Bangerter succeeded in mastering the
problem.
Bangerter’s clock is unquestionably a triumph of human ingenuity. It is a
mechanical masterpiece. Herewith follows the complete specification:
SPECIFICATION
TO ALL WHOM IT MAY CONCERN:
Be it known that I, FRIEDRICH BANGERTER, of the City of New
York (Borough of Richmond), County of Richmond and State of New York,
have invented certain new and useful improvements in
APPARATUS FOR THE EDUCTION, STORAGE
AND APPLICATION OF ENERGY FROM
EXPANSIBLE MATERIALS,
of which the following is a full, clear and exact specification, such as will
enable others skilled in the art to which it appertains to make and use the
same.
This invention relates to apparatus whereby energy may be educed from
expansible materials, due to the expansion and contraction thereof on
changes of temperature, and the said energy either applied direct or stored
and applied for the purpose of operating machines and devices of various
kinds.
I show and describe herein two forms of apparatus for obtaining such
expansion and contraction and the required energy therefrom, and I also
show two forms in which the energy so obtained is accumulated and stored.
In connection therewith, I show the application of my invention to the
running of clocks, but it will be understood that the invention is not limited
in its application to that particular class of machine, and that it may be
applied to any use of which it is susceptible.
It is well known that all metals are capable of some degree of expansion
and contraction, and some metals have this property in greater degree than
others. The amount of expansion for each degree rise in temperature is quite
regular, and is called the co-efficient of expansion. It is also well known
that zinc has this property in greater degree than any other of the solid
metals, its co-efficient of linear expansion being appreciably higher. For this
reason, as well as because of its relatively low cost, I preferably make use
of zinc in the construction of the expansible parts of my apparatus.
One of the objects of my invention, therefore, is to provide an expansion
device of novel construction and arrangement, which will generate energy
and maintain motion during changes in temperature, to such an appreciable
and useful amount, as to constitute it in fact a temperature motor.
A further object of my invention is to provide means for accumulating or
storing the energy thus generated.
A further object is to provide means for applying the energy thus
generated and stored.
Other objects, such as compactness, durability and comparatively low
cost of the apparatus, will appear in the following description, in which
reference is had to the accompanying drawings.
In the drawings:—
Fig. 1 is a front elevation, showing the application of my invention to a
clock provided, in this case, with a mainspring as usual;
Fig. 2 is a rear elevation of the same with a part removed;
Fig. 3 is an enlarged perspective detail showing how the strips forming
part of the expansion member or coil are connected up;
Fig. 4 is a sectional view, on lines 5—5 of Fig. 1;
Fig. 5 is an enlarged detail elevation, with parts removed;
Fig. 6 is an enlarged detail cross section of the central portion of the
apparatus, with part broken away;
Fig. 7 is a rear elevation of the same with parts broken away;
Fig. 8 is an enlarged detail of the upper portion of the apparatus shown
in Fig. 4, with parts removed;
Fig. 9 is a perspective detail, partly broken away;
Fig. 10 is an enlarged detail of a portion of the ratchet mechanism shown
in the lower portion of Figs. 6 and 7;
Fig. 11 is an enlarged section of a flexible coupling shown in Fig. 7;
Fig. 12 is an elevation of a modification of the expansion coil;
Fig. 12ª is a perspective view showing how two of such modified
expansion coils may be connected;
Fig. 1.
BANGERTER’S PERPETUAL TIME CLOCK
Fig. 13 is a front elevation showing my invention applied to another
form of force storage mechanism;
Fig. 14 is a plan view of same, on lines 14—14 of Fig. 13;
Fig. 15 is a rear elevation on lines 15—15 of Fig. 14;
Fig. 16 is a vertical section on lines 16—16 of Fig. 14;
Fig. 17 is an enlarged detail of part of the apparatus shown in the upper
portion of Fig. 16;
Fig. 18 is an enlarged detail of the ball-discharging means shown in the
lower portion of Fig. 16;
Fig. 19 is an enlarged detail of the loading device shown in the opposite
part of the lower portion of Fig. 16; and
Fig. 20 is a plan view on lines 20—20 of Fig. 13.
Referring to the construction illustrated in Fig. 1 to 11, inclusive, B
represents the outer frame of the apparatus.
Mounted within the outer frame B is an inner frame comprising the
uprights C, C¹, which are rigidly secured by cross-bars D¹, D².
The outer frame B, as well as the inner frame uprights C, C¹ are
preferably formed of wood or other material capable of a low degree of
expansion.
Within the upper and lower ends of the inner frame are anti-friction
knife-bars E, E¹, the upper one of which, E, has each end within a vertically
disposed slot E² in the uprights C, C¹, within which said knife-bar may be
moved vertically, as hereinafter described.
Each end of the lower knife-bar E¹ lies immovable within a recess in a
plate E³ mounted on each of the uprights C, C¹.
These knife-bars, which are preferably formed of hardened steel, have
oppositely disposed relatively sharp edges E5, which act as bearings for a
series of horizontally disposed anti-friction levers, F, F¹, which I will term
balance-levers, since they are intended to balance evenly and freely on the
thin edges of the knife-bars with little friction somewhat in the nature of a
scale-balance. These levers are pivotally connected to a series of metallic
expansion strips G, G¹, G², G³, etc., the construction and arrangement and
manner of connecting up the same being more clearly shown in Fig. 3.
It will be observed that the arrangement of the levers F and expansion
strips G, G¹, etc., is such as to form, in effect, a spiral, the short strip G
being connected to one end of one of the balance-levers F, and the strip G
being connected at its lower end to the opposite end of said lever, the upper
end of said strip G¹ being connected to one end of the first one of the levers
F¹. To the opposite end of said lever F¹ the upper end of strip G² is
connected, the lower end of said strip being connected to the left-hand end
of the second one of the levers F, and so on to the final short strip Gx. The
levers F, F¹ must be formed of a metal capable of withstanding great strain
without bending, and for this purpose I prefer to use the metal known as
macadamite.
For convenience of designation, I will refer to each of these groups of
balance-levers F, F¹, and expansion strips G, G¹, etc., as expansion coils,
and while I have herein shown but two sets of such expansion coils, it is to
be understood that there may be any number of such sets desired, and any
desired number of strips and levers composing such coils, depending upon
the character of the work to be performed.
Furthermore, I desire it to be understood that when I use the terms
“strips"—as characterizing the members connecting the balance-levers—
either in the specification or claims, I do not limit myself to the form of
connecting member or “strips” shown, but mean to include in the use of the
term “strips” any other form such as wires, rods or bars of either square,
round, hexagonal or other cross sectional shape.
The ends of the short strips G, Gx are connected by wires H, H¹ with the
opposite ends of what I will term a coil lever I, which, as more clearly
shown in Fig. 5, is keyed to a shaft J, which latter has its end journaled
upon the cross-bars J¹, J² secured to the uprights C, C¹ of the inner frame of
the apparatus, and this shaft I will name a coil shaft.
Keyed to the coil shaft J is a lever K, which it may be proper to
designate as a stress lever, since from it is suspended a weight K¹, the
function of which is to place a certain amount of stress upon the series of
expansion strips and balance-levers composing the expansion coil, keeping
the metal of the strips slightly stretched and preventing any loss of motion
at the different points of connection, and thereby furthering a very
important object, which is to make of each series of expansion strips
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com