Question: Homework CSC 4101 In Chapter 1, we studied how programming languages are evaluated. One of the main criteria for evaluation of programming languages is readability.

Homework CSC 4101

In Chapter 1, we studied how programming languages are evaluated. One of the main criteria for evaluation of programming languages is readability. In this homework, we will evaluate the readability of the Python programming language. That is, how easy, or how hard, it is to read and understand Python programs.

The code below sorts a list of integers. For example, given the list [0,2,4,3], it sorts it to [0,2,3,4] (in increasing order). Can you figure out the algorithm underlying this code; especially the algorithm behind the function recursivestacksortpermutation? To sort the list [2,1,3], mymainprogram needs to invoke recursivestacksortpermutation once (which is printed as count). This invocation occurs within the while loop. How many times does recursivestacksortpermutation need to be invoked to sort [2,3,1]? Describe the algorithm in English and using a flowchart. Based on your experience in deciphering the algorithm, write a paragraph arguing for the readability (or unreadability) of Python.

Even if you are not able to decipher the algorithm correctly it is OK, as long as you can write a convincing paragraph on the readability (or unreadability) of Python with solid arguments. Because this assignment is not about the algorithm, but about the readability of the Python programming language. Should be 1- 1 1/2 pages

"""

Created on Fri Feb 12 21:27:47 2021

@author:

"""

def isemptyPermutation(permutation):

return(len(permutation)==0)

def recursivestacksortpermutation(permutation):

if isemptyPermutation(permutation):

return permutation

elif len(permutation)==1:

return permutation

else:

a = max(permutation)

i = permutation.index(a)

outlist = []

outlist.append(a)

outlist = recursivestacksortpermutation(permutation[i+1:len(permutation)])+outlist

if i>=1:

outlist = recursivestacksortpermutation(permutation[0:i])+outlist

else:

outlist = [] + outlist

return outlist

def isSorted(mylist):

if (len(mylist)==0):

return True

else:

mylist1 = mylist[:]

mylist1.sort()

if (mylist1 ==mylist):

return True

else:

return False

def getinput():

mylist = []

# number of elements as input

n = int(input("Enter number of elements : "))

# iterating till the range

for i in range(0, n):

ele = int(input())

mylist.append(ele) # adding the element

print("input list is:",mylist)

return mylist

def mymainprogram():

mylist = getinput()

count = 0

if isSorted(mylist):

print("sorted list is", mylist)

print(count)

else:

while (not isSorted(mylist)):

count = count+1

mylist = recursivestacksortpermutation(mylist)

print("sorted list is", mylist)

print (count)

mymainprogram()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!