Project #76000 - 6 Python Programming Questions

Here are the quesstions : 

Note, a comment is a piece of text that is preceded by the # symbol and is used to provide information to any human who might read the code. The JES interpreter ignores comments completely.

PROBLEM 1: Giza

                           

Function Name: ​pyramid

  

Parameters: ​int ­ an integer

 

Return Value: ​the number of bricks in the pyramid

 

Description: You’ve always been curious about the number of blocks in the Great Pyramid and​ now you’re about to find out. Create a function that takes in an integer number of rows and calculates the total number of blocks needed to construct the pyramid. A three row pyramid would have the following number of blocks: row 1 = 1 block; row 2 = 4 blocks; row 3 = 9 blocks. Use recursion.

 

Test Cases:

 

>>> pyramid(3)

14

>>> pyramid(35)

14910

 

PROBLEM 2: Hey now, you’re an AllStar!

 

Function Name: ​allStar

  

Parameters: ​str ­ a string

 

Return Value: ​the final string output

 

Description: ​You want to make your text look more interesting to outshine your friends. Write a function that uses recursion to add an asterisk between each letter in the string. 

 

Test Cases:

 

>>> allStar("abc")

'a*b*c'

>>> allStar("smashmouth")

's*m*a*s*h*m*o*u*t*h'

 

 

 

PROBLEM 3: Only Parenthesis!

 

Function Name: ​parenBit

 

Parameters: ​phrase ­ a string

 

Return Value: ​The final string output

 

Description: ​Given a string that contains a single pair of parenthesis, compute recursively a new string made of only of the parenthesis and their contents, so "xyz(abc)123" yields "(abc)". 

 

Test Cases:

>>> parenBit("124242412(abc)2354ikjn23kn5k3")

(abc)

>>> parenBit("asfcasfdweaw4cwcsdfc(key)kjnasfknsdkfnsd") (key)

 

PROBLEM 4: Counter

 

Function Name:​ xCounter()

  

Parameters: ​phrase ­ a string

 

Return Value: ​the number of x’s in the string

 

Description: ​Recursively find the number of x’s in the string passed into the function.

 

Test Cases:

>>> xCounter(“jxujfjkakjxnxxkjnadf”)

4

>>> xCounter("Thxis isx a texst")

3

 

 

           

PROBLEM 5: 99 Bottles of...

 

Function Name: ​codingSong

  

Parameters: ​n ­ an integer to start the song with

 

Return Value: ​none

 

Description: “99 bottles of pop on the wall, 99 bottles of pop! Take one down, pass it around,​    

98 bottles of pop on the wall!” Remember that song? We can’t seem to get it out of our heads. In fact we rewrote it as a catchy song about coding. Sometimes we can’t quite remember the words, so we need you to write a recursive function that prints out the lyrics to the song. Look below for the lyrics and formatting. The second and third lines of each verse begin with tabs. 

 

Test Cases:

>>> codingSong(5)

5 lines of code in my file, 5 lines of code!

Look at this error I've found, I'm backspacing now!

4 lines of code in my file!

4 lines of code in my file, 4 lines of code!

Look at this error I've found, I'm backspacing now!

3 lines of code in my file!

3 lines of code in my file, 3 lines of code!

Look at this error I've found, I'm backspacing now!

2 lines of code in my file!

2 lines of code in my file, 2 lines of code!

Look at this error I've found, I'm backspacing now!

1 line of code in my file!

1 line of code in my file, 1 line of code!

Look at this error I've found! I'm backspacing now!

0 LINES OF CODE IN MY FILE!

 

 

 

 

 

 

 

 

 

PROBLEM 6: Big O

 

This problem is not a function, but should be written in comments at the end of your homework!

 

Description: ​Big O notation is a pretty important concept that helps computer scientists decided how fast an algorithm can handle different sized parameters. Below you will find some functions. At the end of your hw08.py file, use comments to write the function number and then the Big O of the funciton.

 

Example:

### This is the end of my hw08.py document

### Notice how this section is commented out

###

### 1. (Big O of function 1 goes here)

### 2. (Big O of function 2 goes here)

### 3. (Big O of function 3 goes here)

 

Function 1: 

def shortest(list):   shortest = list[0]

  for each in list:

    if len(each) <= len(shortest):

      shortest = each

  return shortest

 

Function 2:

def multiplicationTables(n1,n2):

  for a in range(n1):

    for b in range(n2):

     print str(a) + " x " + str(b) + " = " + str(a*b)

 

Function 3:

def thatsAFact(param):

 

  return 42 

Subject Computer
Due By (Pacific Time) 07/09/2015 11:00 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy