Skip to content

Instantly share code, notes, and snippets.

@BlackGoku36
Last active August 31, 2019 08:22
Show Gist options
  • Save BlackGoku36/92daad21b1851d5dba793d2e58407f61 to your computer and use it in GitHub Desktop.
Save BlackGoku36/92daad21b1851d5dba793d2e58407f61 to your computer and use it in GitHub Desktop.
My first ever python script that i created long time ago, comments and all are left untouched
#.....................................................................................................
#......................If using python 3 than change raw_input() to just input()......................
#.....................................................................................................
import time
#import time is used to get time
#Exchange rate is set to float because float contain decimals point while int dont have decimal point
exchangeRate = float(63.819)
def usd_to_rupee():
print("Enter your amount: ")
while True:
try:
amountEntered = float(input())
break #except is used to handle error
except ValueError:
print("You Got to try inserting numerical Value")
except KeyboardInterrupt:
SystemExit(0)
amount1 = amountEntered * exchangeRate
print(amountEntered, "USD is equal to ", amount1, "INR")
print("")
time.sleep(0.5)# 0.5 means 0.5 second changing to to 1 will make it wait 1 sec before running function, sleep means wait
converter()
def rupee_to_usd():
print("Enter your amount: ")
while True:
try:
amountEntered = int(input())
break
except ValueError:
print("You Got to try inserting numerical value")# again this is used to handle error
except KeyboardInterrupt:
SystemExit(0)
amount2 = amountEntered/exchangeRate
print(amountEntered, "INR is equal to ", amount2, "USD")
time.sleep(0.5)
converter()
def converter():
print("Press 1 to convert USD to INR\n Press 2 to convert INR to USD\nIf you want to quit press '3'")
while True:
try:
convert = int(input())
break
except ValueError:
print("You Got to try inserting 1 , 2 or 3")
except KeyboardInterrupt:
SystemExit(0)
if convert is 1:
usd_to_rupee()
elif convert is 2:
rupee_to_usd()
elif convert is 3:
quit()
else:
retry()
def finish():
quit(converter())
#This will retry if value is other than 1,2,3. Such as 'e','6'.
def retry():
print("Only use '1', '2', '3' ")
converter()
converter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment