Lecture-9-InputOutput
Lecture-9-InputOutput
• Last Class:
• Motivation
• Introduction to Hardware Basics & Programming
Languages
• Writing Simple Python Commands
• Today’s Class:
• Basic Elements of Python Programs: Literals,
Assignments, Datatype Conversion, Identifiers, and
Expressions
>>> print("Hello")
Hello
>>> print("Programming is fun!")
Programming is fun!
>>> print(3)
3
>>> print(2.3)
2.3
>>> x = 2
>>> y = 3
>>> x = y
X CANNOT be done with
two simple assignments
>>> y = x
>>> x
3
>>> y
3
>>> x = 10
>>> X = 5.7
>>> print(x)
10
>>> print(X)
5.7
>>> for = 4
File "<stdin>", line 1
An example… for = 4
^
SyntaxError: invalid syntax
>>> x = 2 + 3
This is an expression that uses the
>>> print(x)
addition operator 5
>>> print(5 * 7)
This is another expression that uses the
35
multiplication operator >>> print("5" + "7")
57
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Float Division
** Exponentiation
abs() Absolute Value
// Integer Division
% Remainder
# Input
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Addition
sum_result = num1 + num2
print("Addition result:", sum_result)
# Subtraction
sub_result = num1 - num2
print("Subtraction result:", sub_result)
# Multiplication
mul_result = num1 * num2
print("Multiplication result:", mul_result)
25/08/23 33 Indian Institute of Technology Patna
Write down a python program to take input of two numbers in
two different integers, swap them and print
# Input
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
• A Python module file is just a text file with a .py extension, which
can be created using any program for editing text (e.g., notepad
or vim)
• Functions- Part I