This commit is contained in:
waldek 2022-05-02 16:37:00 +02:00
parent f8e18a62c7
commit d4c452f6c7
1 changed files with 35 additions and 36 deletions

View File

@ -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) ✗
```
<details>
<summary>Spoiler warning</summary>
```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...")
```
</details>
# Coding challenge - Celsius to Fahrenheit converter
Your first challenge!
@ -496,42 +531,6 @@ else:
</details>
# 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) ✗
```
<details>
<summary>Spoiler warning</summary>
```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...")
```
</details>
## 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)?