100% found this document useful (1 vote)
250 views2 pages

Python LAB Exercises: Sample Output

The document contains 4 Python exercises covering various Python programming concepts and tasks. Exercise 1 involves data types, logical/comparison operators, and calculating distance between points using Pythagorean theorem. Exercise 2 differentiates between built-in and user-defined functions, imports math functions to perform operations, and defines a function to calculate sum, product, difference, quotient, and remainder of input numbers. Exercise 3 uses while loops for countdown, finds sum of primes below a number, and calculates even terms sum in Fibonacci sequence not exceeding 4 million. Exercise 4 counts characters in a string using loops and performs various string operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (1 vote)
250 views2 pages

Python LAB Exercises: Sample Output

The document contains 4 Python exercises covering various Python programming concepts and tasks. Exercise 1 involves data types, logical/comparison operators, and calculating distance between points using Pythagorean theorem. Exercise 2 differentiates between built-in and user-defined functions, imports math functions to perform operations, and defines a function to calculate sum, product, difference, quotient, and remainder of input numbers. Exercise 3 uses while loops for countdown, finds sum of primes below a number, and calculates even terms sum in Fibonacci sequence not exceeding 4 million. Exercise 4 counts characters in a string using loops and performs various string operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 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