Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Licence CC BY-NC-ND Thierry Parmentelat & Arnaud Legout Inria - UCA

exercice - niveau intermédiaire

On se propose d’écrire une classe pour représenter les chiffres romains :

Pour les cas de débordement (par exemple si on ajoute 2000 et 2500), on choisit de représenter le résultat par

Notes importantes

# ATTENTION à ceci !!
# ce n'est pas un bug, c'est par design
# deux trucs indéfinis ne peuvent pas être égaux !

from math import nan

nan == nan
False
# pour tester si quelque chose est indéfini
# utiliser cette fonction

from math import isnan

isnan(nan)
True
# enfin pour info (on n'en a pas besoin ici)
# les mêmes symboles sont dispos dans numpy 

import numpy as np

np.isnan(nan), isnan(np.nan)
(np.True_, True)
from corrections.cls_roman import exo_roman
exo_roman.example()
Loading...

# votre code

class Roman:
    
    def __init__(self, letters_or_integer):
        ...
# correction
exo_roman.correction(Roman)
Loading...

# peut-être utile pour debugger ?
raw = """
MCMXXXIX=1939
MCMXL=1940
MCMXLI=1941
MCMXLII=1942
MCMXLIII=1943
MCMXLIV=1944
MCMXLV=1945
MCMXLVI=1946
MCMXLVII=1947
MCMXLVIII=1948
MCMXLIX=1949
MCML=1950
MCMLI=1951
MCMLII=1952
MCMLIII=1953
MCMLIV=1954
MCMLV=1955
MCMLVI=1956
MCMLVII=1957
MCMLVIII=1958
MCMLIX=1959
MCMLX=1960
MCMLXI=1961
MCMXCVIII=1998
MCMXCIX=1999
MM=2000
MMI=2001
MMII=2002
MMIII=2003
MMIV=2004
MMV=2005
MMVI=2006
MMVII=2007
MMVIII=2008
MMIX=2009
MMX=2010
MMXI=2011
MMXII=2012
MMXIII=2013
MMXIV=2014
MMXV=2015
MMXVI=2016
MMXVII=2017
MMXVIII=2018
MMXIX=2019
MMXX=2020
MMXXI=2021
MMXXII=2022
MMXXIII=2023
MMXXIV=2024
MMXXV=2025
MMXXVI=2026
MMXXVII=2027
MMXXVIII=2028"""
for line in raw.split():
    l, n = line.split('=')
    if Roman(l) != Roman(n):
        print(f"OOPS with {Roman(l)} != {Roman(n)}")
OOPS with <__main__.Roman object at 0x7f6af9f15190> != <__main__.Roman object at 0x7f6af9f15190>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f17aa0> != <__main__.Roman object at 0x7f6af9f17aa0>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f17aa0> != <__main__.Roman object at 0x7f6af9f17aa0>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16570> != <__main__.Roman object at 0x7f6af9f16570>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>
OOPS with <__main__.Roman object at 0x7f6af9f16b70> != <__main__.Roman object at 0x7f6af9f16b70>
OOPS with <__main__.Roman object at 0x7f6af9f14920> != <__main__.Roman object at 0x7f6af9f14920>