diff --git a/learning_python3.md b/learning_python3.md index 8424ddc..e665d41 100644 --- a/learning_python3.md +++ b/learning_python3.md @@ -444,6 +444,41 @@ What about one that takes floating point numbers? * [realpython](https://realpython.com/python-conditional-statements/) conditional logic +# 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 + +```python +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...") +``` + +
+ # Coding challenge - Celsius to Fahrenheit converter Your first challenge! @@ -496,42 +531,6 @@ 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 - -```python -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...") -``` - -
- - ## Some links to read up on * how to convert string to float, Look at the response here: [str.isfloat()](https://stackoverflow.com/questions/736043/checking-if-a-string-can-be-converted-to-float-in-python)?