Question: 2. In python, there are 5 errors to find. Find all of the errors and fix the script. ########### # This program accepts the number

2. In python, there are 5 errors to find. Find all of the errors and fix the script.

########### # This program accepts the number of sides of a dice from a user. It also # accepts how many times the user wishes to roll the dice. It then displays # how many times each side was rolled to the user. It has very useful code # to check if the user inputs an integer. That function is correct. ########### import random def main() : numSides = checkInputInt("How many sides to your dice? [Must be integer]: ') counters = countInputs(numSides) printCounters(counters) print 'Program has Ended' def countInputs(sides) : counters = [0] * (sides) # counters[0] is not used. userInput = checkInputInt('Please enter how many times you wish to roll the dice: ' for x in range(1,userInput+1) : # Generates a random roll roll = randint(1,sides) # Increment the counter for the roll value. counters[roll] = counters[roll] + 1 return counters ## Prints a table of die value counters. # @param counters a list of counters. counters[0] is not printed. # def checkInputInt(userPrompt): x = None while not x: try: x = int(raw_input(userPrompt)) return x except ValueError: print 'You did not enter an integer' def printCounters(counters) for i in range(1, len(counters)) : print("%2d: %4d" % (i, counters[i])) # Start the program. main()

3. Complete the Exercise in Python

Exercise 2.8: Area of rectangle versus circle

Consider one circle and one rectangle. The circle has a radius r = 10.6. The rectangle has sides a and b, but only a is known from the outset. Let a = 1.3 and write a program that uses a while loop to find the largest possible integer b that gives a rectangle area smaller than, but as close as possible to, the area of the circle. Run the program and confirm that it gives the right answer (which is b = 271).

4. Create a 5x5 sized 2D list full of zeroes.

import matplotlib.pyplot as plt

def initList(colSize,rowSize):

# 2nd and 3rd arguments are starting location of mouse in maze of size 8x8

# starting cell is (x,y)

return [[0]*colSize for x in xrange(rowSize)]

#return [[0]*colSize]*rowSize

def printList(list1,colSize,rowSize):

for i in range(0,rowSize):

for j in range(0,colSize):

print list1[i][j], # the comma (,) does not print a newline

print ' '

def scatter(list1,list2,opt1,opt2,opt3):

plt.plot(list1,list2,opt1)

plt.xlabel(opt2)

plt.ylabel(opt3)

plt.show()

#Example use

#sampleList = initList(4,7)

#printList(sampleList,4,7)

'''or imported as library

import hwFunctions

sampleList = hwFunctions.initList(4,7)

hwFunctions.printList(sampleList,4,7)

'''

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!