(Ge8151)
(Ge8151)
First Semester
Civil Engineering
(Regulations 2017)
9. Define a file and give the basic file operations in proper order to be performed
on a file in python language.
PART B — (5 13 = 65 marks)
11. (a) (i) Write a recursive algorithm to find the factorial of a given number.
(5)
(ii) Write a short note on building blocks of an algorithm. (8)
Or
12. (a) (i) Write a python script to find the roots of a quadratic equation. (5)
(ii) Explain about various datatypes used in Python with example. (8)
Or
(b) (i) Write a python script to swap the values of two variables without
using an intermediate variable. (5)
(ii) Write a python code to find factorial of a number using function. (8)
2 40669
13. (a) Differentiate between linear search and binary search procedures and
write a python script to search for a number in a given list of numbers
using binary search. (13)
Or
14. (a) Write a python script to find the product of two given matrices. (13)
Or
(b) Write a python script to sort N numbers using insertion sort. (13)
15. (a) Write a python script that calculates the average word length in a single
paragraph stored in a text file by the user and stores total number of
words in the paragraph and average word length of the paragraph in
another text file. (13)
Or
(b) Write a python script to toggle the case of the text in an input text file
and save the output in an output text file. (13)
Note : the toggle of text “Hello World!” is “hELLO wORLD!”.
PART C — (1 15 = 15 marks)
Or
(b) The sieve of Eratosthenes is an elegant algorithm for finding all of the
prime numbers upto some limit N. The basic idea is to first create a list of
numbers from 2 to N. The first number is removed from the list, and
announced as a prime number, and all multiplies of this number upto N
are removed from the list. This process continues until the list is empty.
Write a python script that prompts a user for N and then uses the sieve
algorithm to find all the primes less than or equal to N. (15)
—————————
3 40669