Question Details

(solution) Question 2: (5 points) ===================== (Suppose the

Question 2: (5 points)


(Suppose the following is true for this question, even if there are some exceptions in real life.)

French country names are feminine when they end with the letter e, masculine otherwise, except for the following countries which are masculine even though they end with e: le Belize, le Cambodge, le Mexique, le Mozambique, le Zaire, le Zimbabwe. Write a function call add_article that takes as input a string s containing a name of a country and returns a string with article added: le for masculine and la for feminine, such as le Canada and la Belgique. However, if the country name starts with a vowel, use l?; for example, l?Italie. For the following plural countries, use les: les Etats-Unis and les Pay-Bas. You may assume that the strings your functions will be tested with contain proper country names with first letter capitalized and that the only plural countries are Etats-Unis and Pay-Bas.

Testing your function:

>>> add_article("Canada")

'le Canada'

>>> add_article("Cambodge")

'le Cambodge'

>>> add_article("Belgique")

'la Belgique'

>>> add_article("Italie")


>>> add_article("Pay-Bas")

'les Pay-Bas'


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


Testing your function:

>>> factorial(0)


>>> factorial(1)


>>> factorial(2) 


>>> factorial(3) 


>>> factorial(4) 


>>> factorial(5) 


>>> 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])


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



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_v1 and 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:


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=' ')



1 2 3


Question 7: (5 points)


Write a function emphasize that takes as an input a string s and

returns a string with a blank space inserted between every pair of

consecutive characters in s.

Testing your function:

>>> emphasize('v')


>>> emphasize('  song ?  tr a ')

'    s o n g   ?     t r   a  '

>>> emphasize('')


>>> emphasize('very important')

'v e r y   i m p o r t a n t'

>>> emphasize(' really?')

'  r e a l l y ?'


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')


  • >>> 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 

  • if both l1 and l2  have the same number of elements and
  • if the 1st element of l1 is the same as the 1st element of  l2 and
  • if the 2nd element of  l1 is not the same as the 2nd element of  l2 and
  • if the 3rd element of l1 is the same as the 3rd element of  l2 and
  • if the 4th element of  l1 is not the same as the 4th element of  l2 and
  • ?.

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"])


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


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


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


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



Solution details:

This question was answered on: Jan 30, 2021

PRICE: $15 (25.37 KB)

Buy this answer for only: $15

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free solution (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .

About this Question






Jan 30, 2021





We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.


Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.


Order Now