Informatics2-2021/Lab03

A MathWikiből
A lap korábbi változatát látod, amilyen Imran (vitalap | szerkesztései) 2021. március 18., 23:38-kor történt szerkesztése után volt.
(eltér) ←Régebbi változat | Aktuális változat (eltér) | Újabb változat→ (eltér)

Home

Tartalomjegyzék

Exercises

Square List

Write a function that gives square of a list. The function should have one parameter, the list :

  • It returns square of the list
  • If the given parameter is not a list, it returns "The input must be a list!"

Mean nearest

Write a function that finds an element in a list which is the nearest to the mean of the list. There should be one parameter, the list.

Increasing sublists

Write a function that finds increasing sublists with a given length within a given list. The function should have two parameters:

  • a list l
  • and a natural number n
  • return the list of n-long increasing sublists of l

Break down to subtasks:

  • first return the list of all n-long sublists of l
  • Check whether a sublist is increasing

Name conflict

We are throwing a party and there are a lots of unknown people there. We write their names in a list. Write a python function that decides whether there is a duplicate in the names (two person with the same name).

The function should have one parameter: the list of names.

Return True if there are at least two people with the same name, False is all the names are unique.

Hint:

Mind that do not compare ones name to itself, only to other's names.

Pronunciation

In Hungarian there are a lots of vowels and some words are hard to pronounce if there are a lots of consonants in them. For example "elorozza" has a good number of vowels, but the Slovakian "zmrzlina" has too many consonants.

Write a python function that decides whether a word has too many consonants or not.

  • Call the function pronunciation
  • with one parameter: word, the word in question
  • return the string "Hard" if the number of consonants are more (or equal) than twice the number of vowels.
  • return "Easy" otherwise.

Pascal

The Pascal triangle consist of binomial coefficients, find details on Wikipedia.

Write a function that calculates some lines of the triangle and returns it as a list of lists. First list is [1], second is of length 2, and so on.

The function should have one parameter: n, the number of rows to calculate.

For example the result of pascal(4) should be:

   [1],
   [1, 1],
   [1, 2, 1],
   [1, 3, 3, 1]

Use the fact that a coefficient is the sum of the two elements above it.

Replacement

Write a function with two parameters: word is a string, and replaces a list of pairs where every pair is a number-character pair, like: (n, c). You should replace the characters in word according to the replaces. On pair represents that you should replace the nth character to the new letter c.

Return the new word after you performed the replacements.

For example replace [(0, 'm'), (2, 'm'), (3, 'm')] in "puppy" you get mummy.

Name generator

You write a computer game where you have to choose name of your player. The name consists of a first name and a last name where the names come from a given list of possibilities.

Generate all the possible names composed from the list of first names and list of last names.

Személyes eszközök