From 952860942bf3986113ba6237240a88a9fbdb34b9 Mon Sep 17 00:00:00 2001 From: waldek Date: Fri, 12 Nov 2021 12:38:15 +0100 Subject: [PATCH] adds currency converter --- learning_python3.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/learning_python3.md b/learning_python3.md index 63f1556..4774c44 100644 --- a/learning_python3.md +++ b/learning_python3.md @@ -440,6 +440,38 @@ else: +# Coding challenge - Currency converter + +I would like you to write a program that converts EUR to DOLLAR. +You should do this in a **new** python file. +I suggest you call it `euro_to_dollar.py` or something that makes sense to you. +The result of this program *could* be as follows. + +```bash +➜ python_course_doc git:(master) ✗ python3 test.py +How much EUR would you like to convert into DOLLAR? 140 +140 EUR is 159.6 DOLLAR +➜ python_course_doc git:(master) ✗ python3 test.py +How much EUR would you like to convert into DOLLAR? blablabla +That's not a number I understand... +➜ python_course_doc git:(master) ✗ +``` +
+ Spoiler warning +result = input("How much EUR would you like to convert into DOLLAR? ") + +rate = 1.14 + +if result.isdigit(): + eur = int(result) + dollar = eur * rate + print("{} EUR is {} DOLLAR".format(eur, dollar)) +else: + print("That's not a number I understand...") + +
+ + # A text based adventure game We can use conditional logic to create quite elaborate decision processes. @@ -1712,6 +1744,12 @@ for login in my_login_list: print("\t{}: {}".format(key, login[key])) ``` +🏃 Try it +--- + +Go back to you *currency converter* program and add a `dict` with multiple currencies so you can enter one amount to convert and your program gives you how much that is in each currency of the `dict`. + + # Coding challenge - Task manager Can you create me a *task manager* please?