Python 3 - Create a Currency Conversion Program using def and if function.
Tuesday, July 2, 2019
Add Comment
Python 3 - Create a Currency Conversion Program using def and if function.
Create a Currency Conversion With Python. This exercise will explain how to use python to build a simple script to convert currencies from USD to IDR. So, if you are a new user on Python then you can use it for training.
This program is created from Python to convert currencies, the coding is very simple and easy to understand.
Case.
- The program is created using def function and if.
- You must input a number that represents the amount of currency.
- Then choose the conversion menu.
- then, the conversion results will be displayed.
Currency Conversion Source Code.
def konversi(jumlah,mataUang1="IDR",mataUang2="USD"):
global uang,nilai
if (mataUang1=="IDR" and mataUang2=="USD"):
nilai = uang/14500
if (mataUang1=="USD" and mataUang2=="IDR"):
nilai = uang * 14500
return nilai
print('''
Menu konversi uang:
1. USD -> IDR
2. IDR -> USD
''')
uang=int(input("Input jumlah uang : "))
pil=int(input("Input menu : "))
if pil == 1:
konversi(uang,"USD","IDR")
print("Uang Anda yang berjumlah USD ", uang ,"= IDR ", nilai)
elif pil == 2:
konversi(uang,"IDR","USD")
print("Uang Anda yang berjumlah IDR ",uang ,"= USD ", nilai)
else:
print("Anda memasukkan pilihan yang salah")
print("Program selesai")
0 Response to "Python 3 - Create a Currency Conversion Program using def and if function."
Post a Comment