You are on page 1of 2

Python LAB Exercises

EXERCISE – 1

1. Explain Different types of Data types


2. Write down the logical operators and comparison operators
3. Write a program to compute distance between two points taking input from the user
(Pythagorean Theorem = math.sqrt((X2 – X1)**2 +(Y2 – Y1)**2).

Sample Output:
Test case1:
Enter value of X1: 3
Enter value of X2: 4
Enter value of Y1: 6
Enter value of Y2: 7
Distance between two points is: 1.4142

EXERCISE – 2

1. Differentiate between user defined functions and built in functions


2. Try different ways to import math modules and use the following functions
ceil, floor, fabs, exp, log, log10, pow, sqrt, cos, sin, tan, degrees, radians), using random()
and randint()
3. Define Calc method that takes input as two parameters and prints its sum, multiplication,
subtraction, division and remainder values.

Sample Output:
Test case1:
Enter first number: 10
Enter Second number: 2
Sum of two values : 8
Multiplication of two values: 20
Subtraction of two values: 8
Division of two values: 5
Modulo of two values : 0
EXERCISE – 3

1. Write a program using a while loops to read one number from console, and prints a
countdown from that number to zero.

Sample Output:
Test case1:
Enter a number: 10
Range of numbers : 10 9 8 7 6 5 4 3 2 10

2. Write a program to find the sum of all primes below given number.

Sample Output:
Test case1:
Enter a number: 10
Sum of prime number below 20 is: 17

3. Each new term in the Fibonacci sequence is generated by adding the previous two
terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55,
89, ... By considering the terms in the Fibonacci sequence whose values do not b
4. exceed four million, find the sum of the even-valued terms.

Sample Output:
Test case1:
Enter no.of Fibonacci numbers you want: 10
Fibonacci numbers are: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
The even no’s sum in the range: 44

EXERCISE – 4

1. Write a program to count the numbers of characters in the string using loop

Sample Output:
Test case1:
Enter input string : “IT LAB EXCERCISES”
No.of characters in the String: 17(with spaces)

2. Do the following string operations


(Hint: know all string operations in python get help by help(“str”) in python GUI shell )

You might also like