Re: A little test for you Guys😜

MRAB python at mrabarnett.plus.com
Wed Sep 23 01:56:19 CEST 2015


On 2015-09-23 00:32, Mark Lawrence wrote:
> On 22/09/2015 19:43, Python_Teacher via Python-list wrote:
>> you have 10 minutes😂 Good luck!!
>>
>>
>> 1. What is PEP8 ?
>
> It's the one between PEP7 and PEP9.
>
>>
>> 2. What are the different ways to distribute some python source code ?
>
> Write on sheet of paper, fold into paper dart, throw from window.
>
>>
>> 2 Lists
>
> Tut, tut, tut.
>
>>
>> Let's define the function plural :
>>
>> def plural(words):
>>      plurals = []
>>      for word in words:
>>         plurals.append(word + 's')
>>      return plurals
>>
>> for word in plural(['cabagge','owl','toy']):
>>      print word
>>
>> Question : How could the code of the function plural be optimised?
>
> It is all ready optimised for programmer time so don't bother with it
> unless there are unforeseen bugs.
>
>>
>> 3 Dictionaries
>>
>> Here are two dictionnaries :
>>
>> input = {
>>      'foo1': 'bar1',
>>      'chose': 'truc',
>>      'foo2': 'bar2',
>> }
>> output = {
>>      'bar1': 'foo1',
>>      'truc': 'chose',
>>      'bar2': 'foo2'
>> }
>>
>> Question : Propose a function that returns output when you provide input ?
>
> def function():
>       return input("Who cares?")
>
You have a couple of problems:

1. 'input' is already bound to a dict.

2. From question 2, it's clear that Python 2 is being used, so you
should be using 'raw_input' instead.

[snip]



More information about the Python-list mailing list