VERSION COURTE ET INTERMÉDIAIRE
AVOIR PLUSIEURS CLÉS
#!/usr/bin/env python3
def get_keys(s):
# Lower the user's entry to easily manipulate data
s = s.lower()
# Create a list to simulate multiple keys
numbers = ['uno', 'one', 'um', 'eins', 'ein']
# Lambda for input validation
validator = lambda x: x if x in numbers else 'no-key-found' # return me x if x is found in the list numbers, contratiwise return me 'no-key-found'
dic = {
validator(s):'1',
'no-key-found':'Key does not exist'
}
return dic[validator(s)]
print(get_keys(input('Type in word: ')))
VERSION PLUS SIMPLE
#!/usr/bin/env python3
import sys
def week_days():
# Assets
number_day = ['1', '2', '3', '4', '5', '6', '7']
# Introduction
print('Welcome to the Week Day Finder')
# User input
day = input('Please, enter the day you want to check: ').lower()
WEEK_COLOR = {'RED': '\u001b[31m', 'GREEN': '\u001b[32m'}
# Day validator
days = {
'1' if day in number_day else 'sunday': 'Weekend Day',
'2' if day in number_day else 'monday': 'Week Day',
'3' if day in number_day else 'tuesday': 'Week Day',
'4' if day in number_day else 'wednesday': 'Week Day',
'5' if day in number_day else 'thursday': 'Week Day',
'6' if day in number_day else 'friday': 'Week Day',
'7' if day in number_day else 'saturday': 'Weekend Day'
}
# Logical trial
try:
if days[day] == 'Week Day':
print(WEEK_COLOR['GREEN'], days[day])
elif days[day] == 'Weekend Day':
print(WEEK_COLOR['RED'], days[day])
except KeyError:
print('** Invalid Day **', file=sys.stderr)
def main():
week_days()
if __name__ == '__main__':
main()