2CS404 PSC Lop

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

NIRMA UNIVERSITY

Institute of Technology
B.Tech. Computer Science and Engineering
Practical List
Semester-IV

2CS404 Programming for Scientific Computing [2-0-2-3]

Sr. Practical Title Hours CLO


NO
1. Basic python programming: 04 1,2

a. Write down a python program which demonstrate the following Hours


concepts:
• Print statement including Padding & Alignment aspect
• Mutable and Immutable Object
b. Ask user to input different type of data (int, float, string) and
convert them in other formats.
c. Demonstrate concept of Membership Operators, Identity Operators
& Bitwise Operators.
d. Write a python program which generates student grade report in
console. Take student roll number and marks (out of 100) of 5
courses from user. Calculate the percentage and display grade of the
student. Use appropriate control statements.
Practice Questions:
e. Develop a python program to make a simple calculator using a
conditional loop.
f. Write a python Program that check whether user entered number is
special number or not. For example, Consider the number is 59. First,
find the sum of all digits (5+9=14). Second, find multiplication of all
digits (5*9=45). Then find addition of sum and multiplication of all
digits (14+45=59). If it is same as number itself, than it is a special
number.
2. a. Write a function areaTriangle that takes the lengths of three sides of 02 1,2
the triangle as input parameters and returns the area of the triangle as
Hours
an output. Also, assert that the sum of the length of any two sides is
lesser than the third side. Write a main function that accepts as
command-line arguments and computes the area of a triangle using
the function areaTriangle.
b. Write a function that takes a string as a parameter and returns a string
with every successive repetitive character replaced with a star(*). For
Example, ‘balloon’ is returned as ‘bal*o*n’.
c. Write a function that takes a number as n input parameter and returns
the corresponding text in words; for example, on input 452, the
function should return ‘Four Five Two’. Use a dictionary for mapping
to digits to their string representation.
Practice Questions
d. Write a function that takes two numbers as input parameters and
returns True or False depending on whether they are co-primes. Two
numbers are said to be co-prime if they do not have any common
divisor other than one.
e. Write the function that check whether number is KAPREKAR
NUMBER or not.
KAPREKAR NUMBER: Consider an n-digit number k. Square it and
add the right n digits to the left n or n-1 digits. If the resultant sum is
k, then k is called a Kaprekar number. For example, 9 is a Kaprekar
number since

92 = 81, and 8 + 1 = 9

and 297 is a Kaprekar number since

2972 = 88209 and 88 + 209 = 297.


452 = 2025 and 20 + 25 = 45.
3. User inputs: 02 1,2

a. Write a recursive function that takes x value as an input parameter Hours


and print x-digit strictly in increasing number. [i.e. x = 6 than output
67891011]
b. A car driver, driving at velocity v0, suddenly puts on the brake. What is
braking distance d needed to stop the car? One can derive, using Newton’s
second law of motion or a corresponding energy equation, that
1 𝑣02
𝑑=
2 𝜇𝑔
Make a program for computing d above equation, when the initial car velocity
v0 and the friction coefficient µ are given on the command line. Run the
program for two cases: v0 = 120 and v0 = 50 km/h, both with µ = 0.3 (µ is
dimensionless).
(Note: convert the velocity in m/s)

Practice Questions:

c. The bell shaped Gaussian function,


1 −1 𝑥 − 𝑚 2
𝑓(𝑥) = exp[ ( ) ]
𝑠 ∗ √2𝜋 2 𝑠
is one of the most widely used functions in science and technology. The
parameters m and s > 0 are prescribed real numbers. Make a program for
evaluating this function for different values of s, x and m. Ask the user to input
the values.
d. Team management wants to pick the top 6 batsmen for the next game. Team
management has data of all of their available 11 batsman details. Help the
team management to select the best 6 batsmen (need to make a strategy for
selecting the top 6 players). The format of all the data is shown below. The
first column is showing the playerID, Remaining 10 columns are having
data of run scored by a player in 10 innings. If a player is not selected in
playing 11, then NA is mentioned. PlayerID must be described format.
Generate all the data randomly.
Constrains:
i. All the data is generated randomly.
ii. Make sure while generating the random data that all 11 players
have played at least 2 games.
iii. PlayerID must have 7 characters. The first character is P and the
remaining 6 characters are randomly generated integer number.
iv. Generate 10 random number as innings score.

Statistical data:
i. Calculate a total score made by the player during the last 10 innings and
calculate the average.
ii. Count the no of time players score the run <50, >=50 and <100, >=100
and <150 and >=150

Sample Data:
P100012 101 9 8 7 14 NA NA NA NA 43
P000001 NA NA NA NA 10 63 45 00 10 34
P023401 10 12 4 6 NA NA NA NA NA NA
P679087 9 31 21 4 62 87 47 94 109 20
4. File Handling and exception; 04 1,2

a. Write a python program that reads the contents of the file poem.txt and count Hours
the number of alphabets blank spaces lowercase letters and uppercase letters
the number of words starting from vowel and the number of occurrences of
each word in the file.
b. An organization wants to compute monthly wages to be paid to an employee
in an organization. The input data is provided in two different files. File1
contains permanent employee data about employees (i.e. Empid, name, hourly
wages), and File2 contains working hours information of each employee in the
current month (i.e., empid and hours). Individual elements of data are
separated by commas. Design a python program that reads both the files,
computes the monthly wages of each employee and store in another file. Take
both file names as command line arguments and check the respected
exceptions for the same.
File Format:
File1
1001, Vinay kumar, 40
1002, Rohit sen, 35
1003, Vinita sharma, 28

File2
1001, 250
1002, 0
1003, 125
c. Consider the following formula and evaluate the y value for the range of t
values found in a file with format
𝑦(𝑡) = 𝑣0 𝑡 − 0.5𝑔𝑡 2

File Format:
v0 3.0
t:
0.15592 0.28075 0.36807889 0.35 0.57681501876 0.21342619 0.0519085
0.042 0.27 0.50620017 0.528 0.2094294 0.1117 0.53012 0.3729850
0.39325246 0.21385894 0.3464815 0.57982969 0.10262264 0.29584013
0.17383923

More precisely, the first two lines are always present, while the next lines
contain an arbitrary number of t values on each line, separated by one or more
spaces.
i. Write a function that reads the input file and returns v0 and a list with the
t values.
ii. Write a function that creates a file with two nicely formatted columns
containing the t values to the left and the corresponding y values to the
right. Let the t values appear in increasing order (note that the input file
does not necessarily have the t values sorted).
iii. Make a test function that generates an input file, calls the function for
reading the file, and checks that the returned data objects are correct.
iv. Write a function which handle the exception handling for the availability
of file or not.

Practice Questions :

d. Develop the Python program for the home loan portal as mentioned below:
The portal has following functionalities:
• Scan the user details from the user and store it to UserDetails.txt file.
Refer the below table for format of file.
Name of TEXT file: UserDetails.txt
Format of File:
UserID| UserCompleteName|Password|
HomeLoanAmount|RemainingLoanAmount
Sample Data
ajaypatel|Ajaykumar Patel|Passwordpw|3000000|2000000
bandish|Bandish Shah|Passwordpw|1000000|550000
darshan|Darshan Dave|Passwordpw|750000|700000

• Scan the Loan Payment Details from the user and store it to
LoanPaymentDetails.txt file.
Name of TEXT file: LoanPaymentDetails.txt

Format of File:
UserID|AmoutPaid|Description|DayOfMonth|Month|Year
Sample Data
ajaypatel|35000|April Payment|2|9|2020
bandish|15000|April Payment|7|9|2020
darshan|7500|April Payment|10|9|2020
ajaypatel|37000|May Payment|1|10|2020
bandish|16000|May Payment|3|10|2020
darshan|10000|May Payment|2|10|2020

• Display the summary details of loan repayment for each loan year-
wise.
Format of summary:
Year: <Year here>------------------------------
Name: <userID here>
Complete Name: < UserCompleteName here>
Home Loan Amount: < HomeLoanAmount here>
Current Remaining Loan Amount: < RemainingLoanAmount here>
Loan Repayment Amount in year <Year here>: <total of repayment>
------------------------------------------------------------
i.e.
Year: 2019------------------------------
Name: darshan
Complete Name: Darshan Dave
Home Loan Amount: 750000
Current Remaining Loan Amount: 740000
Loan Repayment Amount in year 2019: 17500
------------------------------------------------------------
Year: 2020------------------------------
Name: darshan
Complete Name: Darshan Dave
Home Loan Amount: 750000
Current Remaining Loan Amount: 700000
Loan Repayment Amount in year 2020: 17500
------------------------------------------------------------
• Display the summary details of loan repayment for each loan year-
wise month-wise.
Format of summary:
------------------------------------------------------------

Year Month Total amount of loan


repayment

Total amount of loan repayment: <Amount>


------------------------------------------------------------
i.e.
------------------------------------------------------------
Year Month Total amount of loan
repayment
2020 4 57500
2020 5 63000
Total amount of loan repayment: 120500

--------------------------------------------------------------
5. a. Define a class Bank that keeps track of bank customers. The class should 02 1
contain the following data member:
Data member Details Hours
name
Name Name of customer
accountNum Account Number
type Account Type
amount Amount deposited in the bank account
interest Interest earned by the customer
The class should support the following methods:
(a) __init__ for initializing the data members.
(b) deposit for depositing money in the members.
(c) withdrawal for withdrawing money from the account
(d) findInterest that determines the interest on the basis of amount in the
account
Amount Interest per annum
(%)
>= 5,00,000 8
>= 3,00,000 and < 5,00,000 7
>=1,00,000 and <3,00,000 5
<1,00,000 3

b. Define a base class Person, having attributes name, birthdate and city.
Define the class Student that derives from Person class which is having
attributes like rollno, branch, totalMarks and year as data member. The class
should contain the instance method __init__ and the percentage with pass
statement. Define two classes Grad and PostGrad which inherit from the
base class Student. Both the classes should define their __init__ method
which asks user to enter totalMarks value and should override the method
percentage of the superclass. Note that totalMarks obtained are out of 600
and 400 for Grad and PostGrad classes respectively.

6. Numpy and Scipy 04 2,3

a. As you know, a magic square is a matrix all of whose row sums, column Hours
sums and the sums of the two diagonals are the same. (One diagonal of a
matrix goes from the top left to the bottom right, the other diagonal goes
from top right to bottom left.) Show by direct computation that if the matrix
A is given by
A=np.array([[17, 24, 1, 8, 15],
[23, 5, 7, 14, 16],
[ 4, 6, 13, 20, 22],
[10, 12, 19, 21, 3],
[11, 18, 25, 2, 9]])
The matrix A has 5 row sums (one for each row), 5 column sums (one for
each column) and two diagonal sums. These 12 sums should all be exactly
the same, and you could verify that they are the same by printing them and
“seeing” that they are the same. It is easy to miss small differences among
so many numbers, though. Instead, verify that A is a magic square by
constructing the 5 column sums and computing the maximum and minimum
values of the column sums. Do the same for the 5 row sums, and compute
the two diagonal sums. Check that these six values are the same. If the
maximum and minimum values are the same, the flyswatter principle says
that all values are the same.
b. Create scientific calculator using numpy and scipy API.

Matplotlib

c. Plot a line graph that shows in the figure for the given data. The runs scored
between two-wicket fall in a one-day international match between India and
England is generated using randomly. Example:
Fall of 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
Wicket
India 5 35 24 0 99 1 35 15 27 14
England 10 55 34 21 2 7 118 29 32 10

Plot:

7. Pandas: 02 2,3

Develop a python program that reads the data from a given CSV file, which Hours
is having phone usage data using a different branded mobile phone.
Determine if the usage patterns for users differ between different devices.
For example, do users using Samsung devices use more call minutes than
those using LG devices?

8. Statistical data analysis 04 3


a. Design a python program which performs the linear regression
Hours
operation on the given data to predict the house price. Also,
visualize the data for different attributes.
b. Design a python program which implements the bisection and false
positioning method.
c. Design a python program that generates the 100 random variables
and finds out the mean, median and mode for the same.
9. Image Processing: 04 3

a. Develop a python program that reads the image, display matrix Hours
representation of an image creates a histogram of the image and apply
the smoothing effect on an image.
b. Develop a python program which takes the video as an argument and
extract all the frames from a video. Select specific frames and
recreate the video, which has selected frames only.

10. Develop a web page using Django, which asks to upload the CSV file and month 02 3
details from a user, which is having an attendance record of 50 employees of a
company. Display the attendance record in HTML tabular form, which is showing Hours
details like employeeID, a Total number of days, Present Days and percentage
details.
CSV details
E001, p,p,p,p,a,a,p……p
E002, p,a,p,p,p,p,p……p
E003, a,p,p,p,p,p,p……a
In HTML page the display looks like
EmpID Total Days Present Days Percentage
E001 30 26 86.67%
E002 30 25 83.33%
E003 30 20 66.67%

You might also like