0% found this document useful (0 votes)
2 views

python IA 2

The document outlines an internal assessment for a Python programming course, including various programming tasks and theoretical questions. It covers topics such as operators, data types, loops, functions, and algorithms, along with specific programming exercises like checking for palindromes and calculating distances. The assessment is divided into parts with a total of 60 marks, focusing on both practical coding skills and conceptual understanding of Python.

Uploaded by

ElakkiyaSruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python IA 2

The document outlines an internal assessment for a Python programming course, including various programming tasks and theoretical questions. It covers topics such as operators, data types, loops, functions, and algorithms, along with specific programming exercises like checking for palindromes and calculating distances. The assessment is divided into parts with a total of 60 marks, focusing on both practical coding skills and conceptual understanding of Python.

Uploaded by

ElakkiyaSruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

VANDAYAR ENGINEERING COLLEGE ii) Write a program to check whether entered string is palindrome or

not. (8)
PULAVARNATHAM, THANJAVUR
Department of Science and Humanities
PART C (1*16=16 marks)
Internal Assessment II 12. (a) i) Elaborate on membership, identity and bitwise operators of
GE3151 Problem Solving and Python Programming python with suitable examples. (12)

YEAR/SEM: I/I Time: 1.30 Hrs ii) Write a program to print the digit at one’s place of a number. (4)
Max. Marks: 60 OR
PART A (9 X 2 =18Marks)
(b) Write a program to perform search operation which sequentially
1. What is the difference between interactive mode and script mode? checks each element of the list until a match is found or the whole list has
2. Mention the features of lists in python. been searched? (16)
3. List the various single valued data types in python.
4. What is an indentation in python? Give an example.
5. What is ‘len’ function? Give example for how it is used on strings.
6. Write a loop that prints numbers 0 to 57 using the range function in
python.
7. Compare return value and composition.
8. Define String immutability.
9. Write a simple function to multiply two numbers in python.

PART B (2*13=26 Marks)


10. (a) i)Explain the python interpreter and interactive mode in detail.(8)
ii) What operator has the highest precedence in Python? (5)
OR
(b) i) Write a python program to calculate the distance between two
points. (8)
ii) Explain the difference Boolean and Bitwise operator types in
Python? (8)

11. (a) i) Explain String Module. (8)


ii) Write a program to find the sum and average of array numbers. (8) PREPARED BY VERIFIED BY HOD
OR

(b) i) Briefly explain about function prototypes. (8)


1. Write a loop that prints numbers 0 to 57 using the range for i in range(len(arr)):
total = total + arr[i]
function in python.
for x in range(1,51):#For loop which runs from 1 to 50 and avg = total / len(arr)
access the number.
print('\nThe Sum Of Array Elements = ', total)
print(x,end=" ")#print the number. print('\nThe Average Of Array Elements = ', avg)
Python program to calculate the average of an array using a while
10. (b) i) Write a python program to calculate the distance loop
between two points.
import numpy as np
This program uses following formula for distance between two
arr = np.random.randint(10, 150, size = 11)
points:
print('The Random Array Genegrated')
Distance Formula = ( (x2 - x1)2 + (y2 - y1)2 )½ print(arr)
Where: (x1, y1) = coordinates of the first point & (x2, y2) =
total = 0
coordinates of the second point i=0

# Python Program to Calculate Distance while i < len(arr):


# Reading co-ordinates total = total + arr[i]
x1 = float(input('Enter x1: ')) i=i+1
y1 = float(input('Enter y1: '))
avg = total / len(arr)
x2 = float(input('Enter x2: '))
y2 = float(input('Enter y2: ')) print('\nThe Sum Of Array Elements = ', total)
print('\nThe Average Of Array Elements = ', avg)
# Calculating distance The Random Array Genegrated
d = ( (x2-x1)**2 + (y2-y1)**2 ) ** 0.5 [123 91 119 131 45 121 48 53 44 60 82]

# Displaying result
print('Distance = %f' %(d)) The Sum Of Array Elements = 917

11.ii) Write a program to find the sum and average of array numbers.
import numpy as np
The Average Of Array Elements = 83.36363636363636

arr = np.array([14, 25, 35, 67, 89, 11, 99])


total = 0
This Python example allows to enter array elements and finds the sum 11.b)ii)Write a program to check whether entered string is palindrome or not.
and average of all array items. str_1 = input (“Enter the string to check if it is a palindrome: “)
str_1 = str_1.casefold ()
import numpy as np rev_str = reversed (str_1)
if (list str_1) == list (rev_str):
arrlist = []
Number = int(input("Total Array Elements to enter = ")) print (“The string is a palindrome.”)
else:
for i in range(1, Number + 1): print (“The string is not a palindrome.”)
value = int(input("Please enter the %d Array Value = " %i))
arrlist.append(value) 12.a) ii) Write a program to print the digit at one’s place of a number.
n=int(input("Enter a number: "))
d=n%10
arr = np.array(arrlist) print("\n The digit at one's place of",n,"is",d)

total = 0
b) Write a program to perform search operation which sequentially checks each
for i in range(len(arr)): element of the list until a match is found or the whole list has been searched?
total = total + arr[i] Linear Search Algorithm
LinearSearch(array, key)
avg = total / len(arr)
for each item in the array
print('\nThe Sum Of Array Elements = ', total) if item == value
print('\nThe Average Of Array Elements = ', avg) return its index
Total Array Elements to enter = 7 Linear Search in Python
Please enter the 1 Array Value = 22 def linearSearch(array, n, x):

Please enter the 2 Array Value = 44 # Going through array sequencially


for i in range(0, n):
Please enter the 3 Array Value = 66
if (array[i] == x):
Please enter the 4 Array Value = 88 return i
return -1
Please enter the 5 Array Value = 99 array = [2, 4, 0, 1, 9]
x=1
Please enter the 6 Array Value = 122
n = len(array)
Please enter the 7 Array Value = 154 result = linearSearch(array, n, x)
if(result == -1):
The Sum Of Array Elements = 595 print("Element not found")
else:
The Average Of Array Elements = 85.0
print("Element found at index: ", result)

You might also like