0% found this document useful (0 votes)
101 views11 pages

Assignment: 18ESC108A Elements of Computer Science and Engineering B.Tech (ASE) Computer Science FET

This document contains an assignment for a course on Elements of Computer Science and Engineering, including the student name and registration number, semester and year, course code and name, and a declaration by the student that the submitted work is their own. It provides an outline of contents for the assignment, which will include solutions to 3 questions related to programming paradigms in Python and an algorithm for an online shopping cart system.

Uploaded by

Cm Pruthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views11 pages

Assignment: 18ESC108A Elements of Computer Science and Engineering B.Tech (ASE) Computer Science FET

This document contains an assignment for a course on Elements of Computer Science and Engineering, including the student name and registration number, semester and year, course code and name, and a declaration by the student that the submitted work is their own. It provides an outline of contents for the assignment, which will include solutions to 3 questions related to programming paradigms in Python and an algorithm for an online shopping cart system.

Uploaded by

Cm Pruthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

ASSIGNMENT

Course Code 18ESC108A


Elements of Computer science and
Course Name
Engineering
Programme B.Tech(ASE)
Department Computer science
Faculty FET

Name of the Student LIKITH S


Reg. No 18ETAS012017
Semester/Year 2ND/2018
Course Leader/s PRABHAKAR A

i
Declaration Sheet
Student Name LIKITH S
Reg. No 18ETAS012017
Programme B.Tech(ASE) Semester/Year 2ND/2018
Course Code 18ESC108A
Course Title Elements of Computer science and Engineering
Course Date to
Course Leader

Declaration

The assignment submitted herewith is a result of my own investigations and that I


have conformed to the guidelines against plagiarism as laid out in the Student
Handbook. All sections of the text and results, which have been obtained from other
sources, are fully referenced. I understand that cheating and plagiarism constitute a
breach of University regulations and will be dealt with accordingly.

Signature of the
Date
Student
Submission date
stamp
(by Examination & Assessment
Section)
Signature of the Course Leader and date Signature of the Reviewer and date

ii
Contents
____________________________________________________________________________

Declaration Sheet ........................................................................................................................ ii


Contents ...................................................................................................................................... iii
Question No. 1 ..............................................................................................................................4
1.1 Overview:........................................................................... Error! Bookmark not defined.
1.2 Solution to the question: .....................................................................................................4
1.3 Discussions /Suggestions/Views/Recommendations........ Error! Bookmark not defined.
1.4 Conclusions ........................................................................ Error! Bookmark not defined.
Question No. 2 ..............................................................................................................................6
2.1 Overview:........................................................................... Error! Bookmark not defined.
2.2 Solution to the question: ................................................... Error! Bookmark not defined.
2.3 Discussions /Suggestions/Views/Recommendations........ Error! Bookmark not defined.
2.4 Conclusions ........................................................................ Error! Bookmark not defined.
Question No. 3 ..............................................................................................................................9
3.1 Overview:........................................................................... Error! Bookmark not defined.
3.2 Solution to the question: ...................................................................................................10
3.3 Discussions /Suggestions/Views/Recommendations........ Error! Bookmark not defined.
3.4 Conclusions ........................................................................ Error! Bookmark not defined.

<Subject Title> iii


Question No. 1

Solution to Question No. 1:


Solution to the question A1.1:
Introduction to programming paradigm in python
Programming paradigm is a way to categorize programming languages by their features, and procedural,
object oriented, functional, logic-based are common paradigms. Among those paradigms, there is always
debates or curiosity of which is better than what2. Although you may not noticed, Python is very flexible on
a programming style - you can code not only in the procedural or the objective oriented but also the
functional style3. Due to this flexibility, it is highly likely that you are going to face the question of “What
programming paradigm should I use?”. The short answer is “you are fine to use ANY style”. However, if you
don’t want to mix match with only disadvantages of each paradigm, it would be nice to know
characteristics of each style. one type of imperative language, is based on the procedure which can be any
series of computational steps4. So basically, you combine these procedures to instruct a computer each
step it has to take to perform a certain task. Procedures are usually modularized by a function definition
which provides very simple interface to be used by others. In other words, programmers can easily
combine modules from different places to create a program. However, since each function has no
relationship with another, it can be placed anywhere, giving programmers a hard task to find the correct
procedure (which may lead duplicated procedures all over the places). In order to solve this problem,
programming languages usually provides a way to containerize related functions (and variables). In Python,
each file behaves as a container (called as a module in Python) thus you can easily organize related items
without difficulty.
Solution to the question A1.2:

Multiple programming paradigm that python supports are

 Imperative in which the programmer instructs the machine how to change its state,
 Procedural which groups instructions into procedures,
 Object-oriented which groups instructions together with the part of the state they operate on,
 Declarative in which the programmer merely declares properties of the desired result, but not how
to compute it
 Functional in which the desired result is declared as the value of a series of function applications,
 Logic in which the desired result is declared as the answer to a question about a system of facts
and rules,
 Mathematical in which the desired result is declared as the solution of an optimization problem

languages that fall into the imperative paradigm have two main features: they state the order in which
operations occur, with constructs that explicitly control that order, and they allow side effects, in which
state can be modified at one point in time, within one unit of code, and then later read at a different point
in time inside a different unit of code. The communication between the units of code is not explicit.

Meanwhile, in object-oriented programming, code is organized into objects that contain state that is only
modified by the code that is part of the object. Most object-oriented languages are also imperative
languages.

In contrast, languages that fit the declarative paradigm do not state the order in which to execute
operations. Instead, they supply a number of operations that are available in the system, along with the
conditions under which each is allowed to execute. The implementation of the language's execution model
tracks which operations are free to execute and chooses the order on its own.

in functional programming, programs are treated as a sequence of stateless function evaluations. When
programming computers or systems with many processors, in process-oriented programming, programs
are treated as sets of concurrent processes acting on logically shared data structures.

Solution to the question A1.3:

Conclusion
As you can see each programming paradigm has pros and cons. Furthermore, in my opinion, by designing
the program architecture carefully, disadvantages of one paradigm can be overcome. In other words, you
don’t have to worry about what paradigm would be better to program in Python (at least it supports most
of paradigms you can use of). You can mix match several paradigms to code a single program, or it is
completely fine to stick with one that is the most familiar to you. However, no matter which strategy you
are applying, there are other things that are waaaay more important: 1. nice documentations, 2. codes
with high readability and 3. pleasant communications to work efficiently with others who also program on
the same code as yours.

<Subject Title> 5
Question No. B1

Solution to Question No. B1:

Solution to the question.B1.1:-


Algorithm for the problem specification
Step 1: Start
Step 2: Create a dictionary containing item name and item id
Step 3: Use for loop to traverse in the dictionary and print the key values of the dictionary to display
the items that is available.
Step 4: Create an empty dictionary name shopping_cart
Step 5: Display user browsing options such as 1.Add item, 2.Remove item, 3.View cart and 4.Check
out
Step 6: Get a user input option
Step 7: Set a condition as while option! =0
Step 8: If the user chooses option 1, get item and quantity of item as a user input
Step 9: Append quantity and item to the shopping_cart dictionary
Step 10: If the user chooses option 2, get the item that has to be removed from the shopping cart as
a user input
Step 11: Delete the item from the shopping_cart dictionary using del (shopping_cart[item])
Step 12: If the user chooses option 3, using for loop traverse the shopping_cat dictionary and display
the selected items with their respective quantities.
Step 13: If the user chooses option 4, using for loop traverse in the shopping_cart dictionary and
display, the items in the shopping cart, item ID, quantity of each item and cost of each item.
Step 14: Initialize total=0
Step 15: Display , Total quantity of items using; total=total+(shopping_cart[item])
Step 16: Set the cost of each quantity to be rupees 75
Step 17: Calculate total cost using; 75*total and assigning it to a variable t1, (t1=75*total)
Step 18: Display tax to be paid using t1*(15/100)
Step 19: Display grand total to be paid using (t1*(15/100))+t1
Step 20: Display thank you note
Step 21: break
Step 22: if option!=0, get user input option
Step 23: else, display shopping over
Step 24: Stop

<Subject Title> 6
Solution to the question.B1.2:-
Implemented algorithm program in Python programming language.
#input

<Subject Title> 7
#Output

Solution to the question.B1.3:-


The functionality of the above program is to create a shopping list which includes item number, Product
name, quantity and price. It also calculates the tax and prints the final amount i.e., the bill.
Here, when 3 pants and 5 sweatshirts are given as input, the python prints the bill and also calculates the
15% tax on it and finally sums up both and prints the total amount.

<Subject Title> 8
Solution to the question.B1.4:-

When option 1 is entered, it asks for the item. When pant is given, it asks for number of items. When it is
given as 3, it again asks to enter option. 1 is entered, python asks for item. Sweat shirt is entered. It asks for
quantity and after that it again asks for option. When given 4, it checks the items in shopping cart and
generates a bill. It calculates tax separately and finally adds its it to the sum and prepares a bill of Rs. 920.
Finally, it prints, Thank you!

<Subject Title> 9
Question No. B2
Solution to Question No. B2:
Solution to the question B2.1:
Algorithm for the given problem specification.
Step 1: Start
Step 2: Create a dictionary (my_dict) containing name of the items as key and item ID as value
Step 3: Sort the dictionary using sorted() built in function
Step 4: Assign the key of the sorted dictionary to a variable named A, as A = sorted(my_dict)
Step 5: Display A
Step 6: Select name of the text file where you have to perform writing action. It is done with
command with open likith.csv’w’ filehandle:
Step 7: Traverse through A, using for loop as for listitem in A:
Step 8: Insert strings present in A, in a single line in the text file using the command
filehandle.write
Step 9: Display writing is completed
Step 10: Close the file and free the memory space acquired by the file using the command
filehandle.close()
Step 11: Stop

Solution to the question B2.2:


#Input

#output

<Subject Title> 10
1.Excel output 2.Text output

Solution to the question B2.3:


The function creates notepad and excel file of the bill items entered.
It creates a csv file of the given data. The function using dictionary sorts the data obtained using built in
command sorted (). The given inputs are (shirts, pant, sweatshirt, footwear) obtained alphabetically at
output. And output is obtained in excel file and text file

<Subject Title> 11

You might also like