SuperTutor

(15)

$15/per page/Negotiable

About SuperTutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Business & Finance See all
Accounting,Business & Finance,Economics,Engineering,HR Management,Math Hide all
Teaching Since: Apr 2017
Last Sign in: 327 Weeks Ago, 4 Days Ago
Questions Answered: 12843
Tutorials Posted: 12834

Education

  • MBA, Ph.D in Management
    Harvard university
    Feb-1997 - Aug-2003

Experience

  • Professor
    Strayer University
    Jan-2007 - Present

Category > Programming Posted 18 May 2017 My Price 9.00

program must run without syntax errors

(python 3)

Your program must run without syntax errors.  The questions that have

syntax errors will receive zero points. More specifically, for each of

the functions below, I have provided one or more tests to test your functions with. To obtain a partial mark your function may not necessarily give the correct answer on these tests. But if your function gives any kind of python error when run on the tests provided bellow, that question will be marked with zero points. 

Your functions will be tested both with provided examples and with some other examples. 

 

Question 3: (5 points)

=====================

Write a function called factorial that takes as input one number, n,

and returns the value n*(n-1)*(n-2)*…*2*1. You may not use the factorial(x) function from the math module. Roll

your own implementation. You may assume that n is a non-negative

integer

Testing your function:

>>> factorial(0)

1

>>> factorial(1)

1

>>> factorial(2)

2

>>> factorial(3)

6

>>> factorial(4)

24

>>> factorial(5)

120

>>> factorial(500) 122013682599111006870123878542304692625357434280319284219241358838584537315388199760 549644750220328186301361647714820358416337872207817720048078520515932928547790757193 933060377296085908627042917454788242491272634430567017327076946106280231045264421887 878946575477714986349436778103764427403382736539747138647787849543848959553753799042 324106127132698432774571554630997720278101456108118837370953101635632443298702956389 662891165897476957208792692887128178007026517450776841071962439039432253642260523494 585012991857150124870696156814162535905669342381300885624924689156412677565448188650 659384795177536089400574523894033579847636394490531306232374906644504882466507594673 586207463792518420045936969298102226397195259719094521782333175693458150855233282076 282002340262690789834245171200620771464097945611612762914595123722991334016955236385 094288559201872743379517301458635757082835578015873543276888868012039988238470215146 7605445407663535984174430480128938313896881639487469658817504506926365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

=====================

Question 4: (5 points)

=====================

Call an integer special if it is non-negative and divisible by four, except that any non-negative integer divisible by 100 is not special unless it is also divisible by 400.  Write a function, special_count, that takes as input a non-empty list l of integers and returns the number of special integers it contains.

Testing your function:

>>> special_count([2020, 600, 800, 22])

2

>>> special_count([44,-1200,100, 0])

2

=====================

Question 5: (5 points)

=====================

If there is a vote at a meeting, there are several possible outcomes

based on the number of yes and no votes (abstains are not counted). If

all the votes are yes, then the proposal passes "unanimously", if at

least 2/3 of the votes are yes, then the proposal passes with "super

majority", if at least 1/2 of the votes are yes, then the proposal

passes by "simple majority", and otherwise it fails. Write a function

called vote that asks a user to enter all yes-s and no-s and

abstained-s and then press enter.  The function then prints the outcome of

the vote. You may assume that the user will enter at least one yes or no vote.

You may assume that the user will enter yes or y for yes votes, no or n for no votes, and abstained for abstained votes. Finally, you may assume that the only words that the user will enter are yes, y, no, n and abstained but in any combination of lower-case/upper-case letters as can be seen in below tests:

Testing your function: (in the tests below the parts that the user enters are in brown)

>>> vote()

Enter the yes, no, abstained votes one by one and then press enter:

 yes Yes yes yes Y abstained abstained y yes yes yes

proposal passes unanimously

>>> vote()

Enter the yes, no, abstained votes one by one and then press enter:

 yes,yes, no,  YES, no, yes, abstained, yEs,  Y,no

proposal passes with super majority

>>> vote()

Enter the yes, no, abstained votes one by one and then press enter:

 abstained no abstained yes no yes no yes yes yes no

proposal passes with simple majority

>>> vote()

Enter the yes, no, abstain votes one by one and then press enter:

 no yes no no no, yes yes yes no

proposal fails

=====================

Question 6: (5+5=10 points)

=====================

Write a function that takes as input a positive integer n, produces n random integers in the range [-100, 100], and prints all those integers, the minimum of all those integers and the average of all those integers.  You should write two versions of this function stats_v1and stats_v2. In stats_v1, you must use a list to store all those random numbers and only then compute the rest. In stats_v2, neither lists nor tuples nor any other way to store all of those random numbers is allowed. In stats_v2 use a for loop and compute the minimum and the average on the “fly”. 

>>> stats_v1(1)

The minimum and the average of the following numbers:

23 

is 23 and 23.0

>>>

>>> stats_v1(3)

The minimum and the average of the following numbers:

88 -10 84 

is -10 and 54.0

>>>

>>> stats_v2(4)

The minimum and the average of the following numbers:

77 69 21 83 

is 21 and 62.5

>>>

>>> stats_v2(4)

The minimum and the average of the following numbers:

31 -52 -58 34 

is -58 and -11.25

Note that by default the print function prints the given arguments and then goes to a new line. You can change this default behaviour of print function by using the keyword argument end=<string>. For example, if you want print function to print an empty space instead of a new line when it finishes use  end=' '. 

For example:

print(1, end=' ')

print(2, end=' ')

print(3)

prints 

1 2 3

=====================

 

=====================

Question 8: (5 points)

=====================

Write a function crypto that takes as an input a string s and returns an encrypted string where encryption proceeds as follows: in the new string the character of s should appear in the following order in the new string: last, first, second_to_last, second, third_from_the_back, third …. See examples below.

Testing your function:

>>> crypto('Good Day')

'yGaoDo d'

>>> crypto('Good Days')

'sGyoaoDd '

>>> crypto(',4?tr')

'r,t4?'

  • >>> crypto('ab')
  • 'ba'
  • >>> crypto('a')
  • 'a'
  • >>> crypto('')
  • ''

=====================

Question 9: (5 points)

=====================

Write a function stranger_things that takes as an input two non-empty lists. The elements of that list can be numbers, strings or boolean values. The function should return True if 

  • ifbothl1andl2  have the same number of elementsand
  • if the 1st element ofl1isthe same as the 1st element of l2and
  • if the 2nd element of l1isnot the sameas the 2nd element of l2and
  • if the 3rd element ofl1isthe same as the 3rd element of l2and
  • if the 4th element of l1isnot the sameas the 4th element of l2and
  • ….

Otherwise, it returns False.

(In other, True is returned if and only if the lists have the same number of elements and every pair of elements of l1 and l2 that are at the same even index have to be the same and every pair of elements of l1 and l2 that are at the same odd index have to be distinct). See few examples below.

Testing your function:

>>> stranger_things([1],[2,"aha"])

False

>>> stranger_things([1,2,True, '7'],[1,False,True,5])

True

>>> stranger_things([1,2,3,4],[1,2,3,4])

False

>>> stranger_things([1,2,4],[1,'2',3])

False

>>> stranger_things([1,2,4],[1,'2',4])

True

Answers

(15)
Status NEW Posted 18 May 2017 06:05 AM My Price 9.00

-----------

Attachments

file 1495090360-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)