Introduction to Hardware, Software, and Programming
Introduction to Hardware, Software, and Programming
To understand computers, it's essential to know about two critical components: hardware and
software.
● Hardware: These are the physical parts of a computer that you can touch.
○ Think of the computer's monitor, keyboard, mouse, and the components inside
the computer case like the CPU (Central Processing Unit), RAM (Random Access
Memory), and hard drive.
○ Hardware is like the body of a computer; it provides the structure and the parts
needed to do tasks.
Note: When we says Memory it means we are talking about the RAM
● Software: This is the set of instructions that tells the hardware what to do.
○ Software is intangible—you can't touch it.
○ Examples include operating systems (like Windows or macOS),
○ Applications (like Microsoft Word or Google Chrome), and games.
○ Software is like the brain of the computer; it makes decisions and processes tasks
using the hardware.
2. What is Programming?
● Programming is the process of giving instruction to machines that will lead to creating
software.
● It's like writing a recipe for the computer to follow.
● Just as a recipe has steps for making a dish, a program has steps that the computer must
follow to perform a task.
Programming languages are tools that allow us to write instructions for computers.
There are many programming languages, each with its own uses. Here's a breakdown of the
main types:
Low-Level Languages:
● Machine Language: This is the language that a computer's hardware understands
directly. It's made up of binary code (1s and 0s). Writing programs in machine language
is very difficult, so it's rarely done by humans.
● Assembly Language: A small step above machine language, assembly language uses
short codes or mnemonics to represent machine instructions (e.g., `MOV`, `ADD`).
Assembly language is still quite complex but easier to understand than pure machine
language.
High-Level Languages:
● Procedural Languages: These languages, like C and Pascal, are designed to follow a
sequence of steps or procedures. They focus on the “how” of the problem-solving
process.
● Object-Oriented Languages: These languages, like Java and Python, use objects (which
bundle data and methods) to design software. They focus on modeling real-world things
as objects in the code.
● Scripting Languages: Languages like JavaScript, Python, and Ruby are often used to
automate tasks. They are usually easier to learn and are commonly used in web
development.
● Functional Languages: Languages like Haskell and Lisp (Name of languages) are designed
to handle complex math problems and focus on using functions to solve tasks. They are
best used when a lot of complicated calculations are required.
When you write a program, it's usually in a high-level language. But the computer only
understands machine language. To bridge this gap, we use compilers, interpreters, and
assemblers.
Compiler:
A compiler translates a high-level language (like C or Java) into machine language all at
once, creating an executable file (like `.exe`). This file can then be run on the computer. The
translation happens before the program is run, so the program runs faster after being compiled.
Example: If you write a program in C, the compiler will turn your C code into machine
code that your computer can execute.
Interpreter:
An interpreter also translates high-level language into machine language, but it does so
line by line, as the program runs.
This means that the program doesn't need to be compiled before running, but it can be
slower because the translation happens during execution.
Example: Python uses an interpreter. When you run a Python script, the interpreter
reads and executes the code line by line.
Assembler:
An assembly language which is basically mnemonics like GO, HALT, JUMP, and NOT code
which is translated to the machine language by programming language translator i.e.,
Assembler. is a program that takes assembly language as source code and converts it into the
bit format i.e machine language which is understandable by the computers. For example NASM
and MASM.
Chapter 1
Introduction to Python Programming
Python is a popular programming language known for being easy to read and write. It's
used by beginners and professionals alike to create websites, automate tasks, analyze data, and
much more. Python is powerful because it has many built-in tools and a large community that
shares useful libraries and resources. Whether you're new to programming or have some
experience, Python is a great language to learn because of its simplicity and versatility.
Python was named after the British comedy group "Monty Python's Flying Circus" which
Guido van Rossum enjoyed watching.
He wanted the language to be fun, in addition to being easy to use.
Over the years, Python has evolved, with Python 2.0 released in 2000, which introduced
many new features like list comprehensions and garbage collection.
In 2008, Python 3.0 was released, which was not backward compatible with Python 2.x
versions. Python 3 introduced many improvements in terms of code readability and consistency,
although the transition from Python 2 to Python 3 took time as developers needed to update
their existing codebases.
Python was developed to meet the need for a versatile, easy-to-learn, and easy-to-use
programming language that could handle various tasks across different domains. The primary
reasons for the growing popularity of Python include:
1. Ease of Learning: Python’s syntax is clean and readable, which makes it accessible to
beginners. Its design philosophy emphasizes code readability and simplicity.
2. Wide Applicability: Python is used in a variety of fields, including web development, data
science, artificial intelligence, automation, scientific computing, and more. It is often the first
choice for prototyping, and due to its simplicity, many educational institutions use it for
teaching programming.
3. Extensive Libraries and Frameworks: Python comes with a rich set of standard libraries and
frameworks like NumPy, Pandas, Django, Flask, TensorFlow, and PyTorch, which accelerate
development in various domains.
4. Quick Prototyping: Python runs on an interpreter system, meaning that code can be executed
as soon as it is written line by line. This means that prototyping can be very quick.
4. Community Support: Python has a large, active community, which contributes to a wealth of
resources, tutorials, and third-party modules. This vibrant ecosystem makes it easier to find help
and collaborate with others.
1.3 Features of Python
Python’s design and functionality offer several features that make it stand out among
programming languages:
1. Simple and Easy to Learn: Python’s syntax is clear, concise, and easy to understand. This
simplicity makes it ideal for beginners and for rapid development.
2. Interpreted Language: Python is an interpreted language, meaning that code is executed line
by line, which makes debugging easier and also fast prototyping.
4. Extensive Standard Library: Python’s standard library includes modules for various tasks like
regular expressions, file I/O, web development, and more, reducing the need for writing code
from scratch.
6. Dynamic Typing: Python is dynamically typed, meaning that the type of a variable is
determined at runtime. This flexibility allows for faster development.
7. High-Level Language: Python abstracts away much of the complexity involved in tasks like
memory management, making it easier to focus on writing code rather than managing
resources.
8. Extensible and Embeddable: Python can be extended with modules written in other
languages like C or C++, and it can be embedded into applications written in these languages.
9. Open Source: There is no need to pay for Python. Python can be freely downloaded from
[Link] website. Its source codes can be read, modified and can be used in programs
as desired by the programmers.
10. Database connectivity: A database represents software that stores and manipulates data.
For example, Oracle is a popular database using which we can store data in the form of
tables and manipulate the data.
Python provides interfaces to connect its programs to all major databases like Oracle, Sybase or
MySql.
11. Good Memory Management: Python runs garbage collector mechanism automatically
hence utilizes memory effectively.
C Language Python
C language does not contain the features like Python is an object-oriented language. It contains
classes, objects, inheritance, polymorphism, features like classes, objects, inheritance,
etc. polymorphism, etc.
It is compulsory to declare the data types of Type declaration is not required in Python.
variables, arrays, etc in C language.
C language does not directly support exception Python handles exceptions and hence Python
handling. programs are robust.
C language has for, while and do_while loops. Python has for and while loops only. It does not
have a do_while loop.
The variable in for loop does not increment The variable in the for loop increments
automatically. automatically.
C language has switch statements. Python does not have a switch statement.
The programmer should allocate and deallocate Memory allocation and deallocation is done
memory using malloc(), calloc(), realloc(), or free automatically by PVM.
functions.
C does not contain a garbage collector. Automatic garbage collector is available in Python.
C supports single and multi-dimensional arrays. Python supports only single dimensional arrays.
Third party applications like numpy should be used
to work with multidimensional arrays.
The array index should be a positive integer. Array index can be positive or negative integer
numbers.
Indentation of statements is not necessary in C. Indentation is required to represent a block of
statements.
A semicolon is used to terminate and a comma New line indicates end of the statement and
is used to separate expressions. semicolon is used as an expression separator.
C is typically used for system programming, Python is used in web development, scripting, data
embedded systems, and applications requiring analysis, and automation.
high performance
JAVA Vs Python
Java programs require more lines. Python programs are short and compact. A big
problem can be written using very less no. of lines.
It is compulsory to declare the data types of Data type declaration is not required in Python.
variables, arrays, etc in Java.
JAVA language has do_while, while, for loops. Python has for and while loops only.
JAVA has switch statement Python Does not have Switch Statement
The variable in for loop does not increment The variable in the for loop increments
automatically. automatically.
Memory allocation and deallocation is done Memory allocation and deallocation is done
automatically by JVM (Java Virtual Machine). automatically by PVM (Python Virtual Machine).
Java supports single and multi-dimensional Python supports only single dimensional arrays. To
arrays. work with multi- dimensional arrays, third party
applications like numpy are used.
An array index should be a positive integer. Array index can be a positive or negative integer
number. Negative index represents locations from
the end of the array.
Indentation of statements is not necessary in Indentation is required to represent a block of
JAVA language. statements.
A semicolon is used to terminate the New line indicates end of statement and semicolon
statements and a comma is used to separate is used as an expression separator.
expressions.
Java is widely used in enterprise applications, Python is preferred for web development, data
Android development, and large systems. science, and scripting.
Understanding the fundamental building blocks of Python is essential for writing efficient and
effective code. These building blocks include keywords, identifiers, variables, comments,
docstrings, indentation, and input-output operations.
1.5.1 Keywords
● Keywords in Python are reserved words that have a special meaning and purpose in the
language.
● They cannot be used as identifiers (names of variables, functions, etc.). Python has a set
of predefined keywords, such as `if`, `else`, `while`, `for`, `def`, `return`, and many more.
● All Reserved words in Python contain only alphabet
● All Keywords are lower case, except the following three
● True
● False
● None
● You can see the list of all keywords in Python by using the `keyword` module:
import keyword
print([Link])
1.5.2 Identifiers
Identifiers are the names given to variables, functions, classes, and other objects in
Python. They must follow specific rules:
- Identifiers can only contain letters (uppercase (A-Z) or lowercase (a-z)), digits(0-9), and
underscores (_).
- They must start with a letter or an underscore, not with a digit.
- Identifiers are case-sensitive (`Variable` and `variable` are different).
- Certain names are reserved and cannot be used as identifiers because they conflict with
Python’s keywords.
Eg.: def = 10
Not valid in python as it is keyword
In case 1 variable is valid as it start with letter and not contains any symbol
1.5.3 Variables
● Variables are containers for storing data values. In Python, you don’t need to declare the
data type of a variable explicitly; the interpreter infers it based on the value assigned:
x = 10 int x ;
x = 10 ;
1.5.4 Comments
● Comments in Python are non-executable statements that are used to explain code and
make it more understandable.
● They are ignored by the interpreter and do not affect the execution of the program.
1.5.5 Docstring
● Declaring Docstrings: The docstrings are declared using ”’triple single quotes”’ or “””
triple double quotes “”” just below the class, method, or function declaration. All
functions should have a docstring.
Following in an example of declaring docstring
def my_function():
"""
This is a docstring. It explains the purpose of the function.
This function prints Hello world
"""
print("Hello, World!")
● Accessing Docstrings: The docstrings can be accessed using the __doc__ method of the
object OR using the help function. The below examples demonstrate how to declare
and access a docstring.
Method 1
def my_function():
'''Demonstrates triple double quotes
docstrings and does nothing really.
It tells what function does '''
print(“Hello word”)
print("Using __doc__:")
print(my_function.__doc__)
Using __doc__:
Demonstrates triple double quotes
docstrings and does nothing really.
It tells what function does
Method 2
def my_function():
'''Demonstrates triple double quotes
docstrings and does nothing really.
It tells what function does '''
print(“Hello word”)
print("Using help:")
help(my_function)
Using help:
Help on function my_function in module __main__:
my_function()
Demonstrates triple double quotes
docstrings and does nothing really.
It tells what function does
1.5.6 Indentation
● Indentation refers to the spaces or tabs at the beginning of a line. Unlike many other
programming languages that use braces `{}` to define code blocks,
● Python uses indentation to determine the grouping of statements.
● Proper indentation is crucial in Python, as it defines the structure and flow of the code:
if x > 0:
print("x is positive") # This is Block of code
else:
print("x is non-positive") # This is Block of code
1.5.7 Input-Output
● Input: The `input()` function is used to take input from the user.
○ It always returns the input as a string.
● >>> name = input("Enter your name: ")
Above instruction will accept the data from the user through the keyboard and will
assign that value to the variable name. Default data type of name will be string only.
This way of writing input instructions is always recommended.
● >>> input(“ENter your name”)
Above instruction will accept the value from the user through the keyboard but the
value will be stored in the memory which we can not use easily further as we do not
have a memory tag for the same. Hence this method is not recommended.
Hello
HelloHelloHello
Welcome to CSMSS
20
5.5
The value of a is = 5.5
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], line 9
7 print(a) # Prints the value of tag a or variable a
8 print("The value of a is = ", a) # Prints the given string and then value in same line
----> 9 print (a+ "Hello") # Will show the error
1. Write a program to read 2 numbers from the keyboard and print sum.
Algorithm:
Step 1: Start the program
Step 2 : Read the two input from user through the keyboard
Step 3: Calculate the Sum
Step 4: Print the result on console
Step 5: Stop the program
Flowchart:
Python Code:
Output:
Homework:
1. Sum of five Numbers: Write a program that takes five numbers as input and outputs
their sum.
2. Product of Two Numbers: Write a program that takes two numbers as input and outputs
their product.
3. Difference Between Two Numbers: Write a program that takes two numbers as input
and outputs the difference between the first and the second number.
4. Square of a Number: Write a program that takes a number as input and outputs its
square.
5. Cube of a Number: Write a program that takes a number as input and outputs its cube.
6. Average of Three Numbers: Write a program that takes three numbers as input and
outputs their average.
7. Perimeter of a Rectangle: Write a program that takes the length and width of a rectangle
as input and outputs its perimeter.
8. Area of a Rectangle: Write a program that takes the length and width of a rectangle as
input and outputs its area.
9. Area of a Triangle: Write a program that takes the base and height of a triangle as input
and outputs its area.
10. Circumference of a Circle: Write a program that takes the radius of a circle as input and
outputs its circumference.
11. Area of a Circle: Write a program that takes the radius of a circle as input and outputs its
area.
12. Convert Celsius to Fahrenheit: Write a program that takes a temperature in Celsius as
input and outputs the temperature in Fahrenheit.
13. Convert Fahrenheit to Celsius: Write a program that takes a temperature in Fahrenheit
as input and outputs the temperature in Celsius.
14. Simple Interest Calculation: Write a program that takes the principal, rate, and time as
input and outputs the simple interest.
15. Compound Interest Calculation: Write a program that takes the principal, rate, and time
as input and outputs the compound interest.
16. Pythagorean Theorem: Write a program that takes the lengths of the two legs of a right
triangle as input and outputs the length of the hypotenuse.
17. Quadratic Equation Roots: Write a program that takes the coefficients of a quadratic
equation as input and outputs the roots of the equation.
18. Number of Seconds in a Day: Write a program that takes a number of days as input and
outputs the total number of seconds.
19. Percentage Calculation: Write a program that takes the marks obtained and total marks
as input and outputs the percentage.
20. Distance Between Two Points: Write a program that takes the coordinates of two points
in a plane as input and outputs the distance between them.
21. BMI Calculation: Write a program that takes the weight and height of a person as input
and outputs their Body Mass Index (BMI).
22. Speed Calculation: Write a program that takes distance and time as input and outputs
the speed.
23. Currency Conversion: Write a program that takes an amount in one currency as input
and outputs the equivalent amount in another currency using a given exchange rate.
24. Time Conversion: Write a program that takes a time in hours and minutes as input and
outputs the total time in minutes.
25. Power Calculation: Write a program that takes a base number and an exponent as input
and outputs the result of raising the base to the exponent.
26. The distance between two cities (in km.) is input through the keyboard. Write a Python
program to convert and print this distance in meters and centimeters.
These problems are great for practicing basic input, output, and arithmetic operations in
Python.
Once the installation is complete, you can verify that Python has been installed
correctly by opening the Command Prompt (search for “cmd” in the Start menu)
and typing the following command:
python - - version
Press Enter, and you should see the version of Python you installed displayed in
the output. This confirms that Python has been successfully installed on your
computer.
For installation refer this links:
a. Installing Jupyter on Windows
[Link]
In this Unit, we explored the basics of Python, starting with its history and the reasons
behind its creation and widespread adoption. We also examined Python's features and how it
compares with other popular programming languages like C and Java. Finally, we covered the
foundational building blocks of Python, including keywords, identifiers, variables, comments,
docstrings, indentation, and input-output operations. Understanding these basics is essential for
anyone starting their journey in Python [Link] the end we have seen how to install
Python various IDEs on windows operating systems.