Python Programming Lab Manual
Python Programming Lab Manual
Lab Objectives:
➢ Two modes for using the Python interpreter: - 1. Interactive Mode 2. Script Mode.
Activity 3. Python Comments
Activity 4. Reading input from the console
Example 1. ➔ Python program which accept your name from keyboard and display it.
str = input('Enter your name:')
Enter your name:
Raj kumar
print(str)
Example 1. Python program which accepts two numbers and perform different arithmetic on it
Enter a value: 10
Enter b value: 5
Output
Addition of a and b 15
Subtraction of a and b 5
Multiplication of a and b 50
Division of a and b 2.0
Remainder of a and b 0
Exponent of a and b 100000
Floar division of a and b 2
Activity 6. Python Data Types
1. Write a program to demonstrate different number data types and string in Python.
Output:
a is Type of <class ‘int’>
b is Type of <class ‘float’>
c is Type of <class ‘complex’>
xy is Type of <class ‘str’>
Activity 6. Python String methods and functions
1. Write a program to create, concatenate and print a string and accessing sub-string from a given string.
Source Code:
s1=input("Enter first String : ");
s2=input("Enter second String : ");
print("First string is : ",s1);
print("Second string is : ",s2);
print("concatenations of two strings :",s1+s2);
print("Substring of given string :",s1[1:4]);
Output:
Enter first String: COMPUTER
Enter second String: SCIENCE
First String is : COMPUTER
Second String is : SCIENCE
Concatenations of two strings : COMPUTERSCIENCE
Substring of given string: OMP
String functions and methods:
Activity 7. Python conditional structure / statement
1. Write a python program which accept one integer number from keyboard then display the number
when number is greater than 0 using python if statement.
Source code
a = int(input ('Enter the number:'))
if a > 0:
Output
Exercise. Write a python program that accept age of a person then display a message "You are
eligible to vote " if and only if the age a person is greater than or equal to 18.
2. Write a python program which accept two integer numbers from keyboard then display which
number is greater using python if-else statement.
a = int(input ('Enter the first number:'))
b = int(input ('Enter the second number:'))
if a > b:
print (a, "is greater than ", b)
else:
print (b, "is greater than ",a)
Exercise. Write a python program that accept age of a person then display a message "You are
eligible to vote ". when that age a person is greater than or equal to 18 or “You are not eligible to
vote" when age is less than 18.
3. Write a python program which accept one number from keyboard then identify that number as
positive, negative, or zero using python if-elif-else statement.
a = input ('Enter the number:')
if a > 0:
print (a, "The number is positive")
elif a<0:
print (a, "The number is Negative")
else:
print (a, "The number is zero")
Exercise
1. Write a python sources code that accept string from the user and apply different string
functions and methods on it.
2. Write a python program that accept one integer number from keyboard (user) and display a
message only when the input number is greater than 100 using if statement condition.
== > message is: “The input number is greater than 100”
3. Write a python program that accept two number from keyboard (user) then compare them
(which number is greater) using if else statement condition.
4. Write a python program that take input from the user then identity the number as number is
even or odd using if else statement.
5. Write a python program that take one number from the user then identity the number as
number is positive, negative or zero using if-elif-else statement.
6. Write a python sources code that accept students score then calculate the grade of the score?
90-100 ========> A
80-89 ========> B
70-79 ========> C
60-69 ========> D
Below 60 =======> F
7. Write a python program which accept your first name and last name and display your first
name and last name on single line?
Note: 1. store your first name on variable fname 2. store your last name on variable lname
and 3. Add space between your name and father name (first name and last name).