• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 6. Lists

Difficulty level:

Task«Rating of dishes»

Imagine that you are helping the jury at the culinary competition. Each participant has the name of the dish, and the jury wants to quickly determine the winner based on the "creativity" of the name. For the assessment, a system is used where each letter in the name of the dish brings points equal to its serial number in the alphabet (a = 1, b = 2, ..., z = 26). rn
You need to write a program that takes a list of names of dishes from participants and determines the dish with the highest" creativity score ".

Input format

the number of participants in the culinary contest (integer)
rn
List of names of dishes, each on a new line (line)

Output format

the name of the dish with the highest "creativity score". rn
The total score of this dish

Example

Input

3
Apple pie
Banana Bread
Chocolate Cake

Output

Banana Bread
80

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Ввод количества участников
n = int(input())

# Инициализируем переменные для хранения лучшего блюда и его балла
best_dish = ""
max_score = 0

# Обрабатываем каждое блюдо
for _ in range(n):
    dish = input()  # Вводим название блюда
    score = 0  # Балл текущего блюда
    # Считаем балл: для каждой буквы в названии
    for char in dish:
        if char.isalpha():  # Учитываем только буквы
            # Позиция буквы в алфавите: a=1, b=2, ..., z=26
            score += ord(char.lower()) - ord('a') + 1
    # Если текущий балл выше максимального, обновляем
    if score > max_score:
        max_score = score
        best_dish = dish

# Выводим название лучшего блюда и его балл
print(best_dish)
print(max_score)

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!