⊗pyPmUFAdv 207 of 208 menu

Tips for Creating Functions in Python

  1. Function names must be verbs.
  2. The name of each function should accurately reflect what the function does.
  3. A function should do only what its name clearly implies, and nothing else.
  4. Each function should perform only one action.
  5. Use helper functions inside functions.
  6. It is better not to make the function code longer than 10-15 lines.
  7. It is better to break long functions into a number of auxiliary ones.
  8. Use common prefixes in function names: show, get, set, calc, create, change, check.
  9. If a function name consists of two or more words, they should be separated from each other by an underscore _, for example, get_sum.
  10. Move duplicate code into functions.

Write down the shortcomings of the following code and fix them:

def func(num1, num2): return num1 * num2

Write down the shortcomings of the following code and fix them:

def user(name): return 'bye, ' + name

Write down the shortcomings of the following code and fix them:

def get_num(num): return str(num)

Write down the shortcomings of the following code and fix them:

def check(lst): sum = 0 for el in lst: if el > 0: sum += el if el < 0: continue else: continue return sum
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline