Informatics2-2021/Lab05

A MathWikiből
(Változatok közti eltérés)
(Új oldal, tartalma: „= Exercises = == Capital Letter == Write a function that has one parameter: word and returns whether it starts with a capital letter or not (return True or False). ==…”)
 
(Capital Letter)
2. sor: 2. sor:
  
 
== Capital Letter ==
 
== Capital Letter ==
Write a function that has one parameter: word and returns whether it starts with a capital letter or not (return True or False).
+
Write a function that has one parameter: <b>word<b> and returns whether it starts with a capital letter or not (return True or False).
  
 
==Bird Talk ==
 
==Bird Talk ==

A lap 2021. március 9., 06:47-kori változata

Tartalomjegyzék

Exercises

Capital Letter

Write a function that has one parameter: word<b> and returns whether it starts with a capital letter or not (return True or False).

Bird Talk

Here is a strange language birdtalk which takes every word from the English language and translates them into bird language. You have to decode a bird word into English. Implement the <b>birdtalk_decode function with two parameters:

  • birdword a word to decode
  • dictionary a list of all known English words which are the possible decoded words. The function should return an English word if it's birdtalk variant is the searched (bird)word. If the birdword is not a translation of any English words, then return None.

The birdtalk is not a complicated language, but the function tobird can do this for us. This function encodes an English word into birdtalk. Don't modify the tobird function, write you code into birdtalk_decode.

CODE:
  def tobird(word):
       vowels = "aeiou"
       birdword = ""   
       for letter in word:       
            if letter in vowels:
                 birdword = birdword + letter + "v" + letter
            else:
                 birdword = birdword + letter
       return birdword
  def birdtalk_decode(birdword, dictionary):


Annagramma

Two words are anagrammas if they consist of the same letters but in a different order. Or they are the same strings.

For example: silent and listen

Write a function with one parameter: a list of words. Return True or False whether there is an anagramma or not.

Someone already wrote the code but there is a mistake in it. Correct the code!

CODE:
  def countletters(word):
      counter = {}
      for letter in word:
          if letter in counter:
              counter[letter] += 1
          else:
              counter[letter] = 1
      return counter
   
  def isanagramma(l):
      for i in range(len(l)):
          for j in range(i+1, len(l)):
              i_count = countletters(l[i])
              j_count = countletters(l[i])
              if i_count == j_count:
                  return True
      return False

Highway Rest

Highway rest According to an EU regulation, there should be a 200 meters long rest place along the road at every 10th kilometer.

There are some rests already built. Write a python function that calculates the amount of additional rests to build. Call that function highwayrest with two parameters:

  • length the length of the road (a positive number)
  • former a dictionary of the formerly built rests. The keys are the points were the rest is and the values are the length of that rest in meters.

It may be that you have to build a new rest place or make an existing rest place longer. The rest stations should be placed at 10, 20, 30... kilometers. If the road is 40 kilometers long then you have to build a rest at the 10th, 20th, 30th and 40th kilometers. If a given rest place is not long enough then you shold build the rest of it. The function should return the amount of newly built rests in meters. "

Point Table

A fellow teacher on the university got COVID-19 and you have to fill in for her. You have to teach her lectures and also grade her students. In order to do that, you need the previous scores of the students that she saved in a .txt file like this:

           | ABC123 | NEPTUN | OMGLOL
  teki     | 4      | 5      | 0
  atment   | 2      | 2      | 0
  huto     | 5      | 5      | 1

You want to store the points in python but you have to convert her tables into some other format. What you need is the total scores so far, per student.

Her tables are as follows: columns are separated by "|" (pipe symbol) The first column is the name of the exercise, this is irrelevant if you need only the sum. The first row contains the Neptun codes of sturents, except the very first cell, which is empty The rest is the score of a given sturent for the given exercise. Write a python function that recieves one big piece of string (the content of her file) and returns the total points of students in a dictionary. The keys should be the neptun codes and the value should be the total points of the exercises.

The function should have one parameter:

  • tabular the content of the txt file as a string

Hint: Use

  • split()
  • strip()
  • Convert from string to integer: int()
Személyes eszközök