lettremax.py

Created by schraf

Created on October 06, 2018

285 Bytes

Écrire une fonction maxi qui admet en paramètre des lettres (pas d’espace ni de ponctuation) et qui en retour affiche en majuscule la lettre la plus loin dans l’alphabet. Par exemple :
>> maxi("BonjourATous")
'U'

car la lettre ‘U’ est bien celle la plus proche de la fin de l’alphabet.


def maxi(mot):
  # Initialisation de la lettre max
  s = "A"
  for c in mot.upper():
    if c > s:
      s = c
  return s

# Version 2

def maxiv2(mot):
  return list(reversed(sorted(mot.upper())))[0]

# Version 3

def maxiv3(mot):
  return sorted(mot.upper())[-1]

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.