|
| 1 | +# exercies 8.3.2 from unit 8 |
| 2 | +''' |
| 3 | +Create a dictionary with a name of your choice and initialize it according to the |
| 4 | +following table: |
| 5 | +
|
| 6 | +Mariah first_name |
| 7 | +Carey last_name |
| 8 | +27.03.1970 (string) birth_date |
| 9 | +Sing, Compose, Act (list) hobbies |
| 10 | +
|
| 11 | +Write a program that performs the following actions, depending on the digit that the user |
| 12 | +pressed: |
| 13 | +
|
| 14 | +Print Maria's last name to the screen. |
| 15 | +Print to the screen the month in which Maria was born. |
| 16 | +Print to the screen the number of hobbies Maria has. |
| 17 | +Print to the screen the last hobby in Maria's list of hobbies. |
| 18 | +Add the hobby "Cooking" to the end of the list of hobbies. |
| 19 | +Turn the date of birth type into a tuple that includes 3 numbers |
| 20 | +(day, month and year - from left to right) and print it. |
| 21 | +Add a new key called age which includes Maria's age and present it. |
| 22 | +Guidelines |
| 23 | +Ask the user to enter an input (a number between 1 and 7) and assume that the input |
| 24 | +is correct. |
| 25 | +''' |
| 26 | + |
| 27 | +def main(): |
| 28 | + # create a dictionary with Maria's information |
| 29 | + mariah = { |
| 30 | + 'first_name': 'Mariah', |
| 31 | + 'last_name': 'Carey', |
| 32 | + 'birth_date': '27.03.1970', |
| 33 | + 'hobbies': ['Sing', 'Compose', 'Act'] |
| 34 | + } |
| 35 | + |
| 36 | + user_input = int(input("Enter a number between 1 and 7: ")) |
| 37 | + |
| 38 | + def perform_action(mariah, user_input): |
| 39 | + if user_input == 1: |
| 40 | + print(mariah['last_name']) |
| 41 | + elif user_input == 2: |
| 42 | + month = mariah['birth_date'].split('.')[1] |
| 43 | + print(month) |
| 44 | + elif user_input == 3: |
| 45 | + print(len(mariah['hobbies'])) |
| 46 | + elif user_input == 4: |
| 47 | + print(mariah['hobbies'][-1]) |
| 48 | + elif user_input == 5: |
| 49 | + mariah['hobbies'].append('Cooking') |
| 50 | + print(mariah['hobbies']) |
| 51 | + elif user_input == 6: |
| 52 | + birth_date = tuple(mariah['birth_date'].split('.')) |
| 53 | + print(birth_date) |
| 54 | + elif user_input == 7: |
| 55 | + mariah['age'] = 2023 - int(mariah['birth_date'].split('.')[2]) |
| 56 | + print(mariah['age']) |
| 57 | + |
| 58 | + perform_action(mariah, user_input) |
| 59 | + |
| 60 | +# call the main function |
| 61 | +main() |
0 commit comments