Skip to content

Instantly share code, notes, and snippets.

@Miha-Pleskovic
Last active July 24, 2016 17:35
Show Gist options
  • Save Miha-Pleskovic/69a0395597e42086eb14f2d0a6499390 to your computer and use it in GitHub Desktop.
Save Miha-Pleskovic/69a0395597e42086eb14f2d0a6499390 to your computer and use it in GitHub Desktop.
Unit Converter
# -*- coding: utf-8 -*-
def converter():
choice1 = raw_input("Which measurements you wish to choose? (1 - Length | 2 - Volume) ")
if choice1 == "1":
length_converter()
elif choice1 == "2":
volume_converter()
else:
print "Please try again."
converter()
try_again()
def length_converter():
number1 = raw_input("Enter your number: ")
if number1.replace(".", "", 1).isdigit() or number1.isdigit():
if number1 == "1":
length_type = raw_input(number1 + " ... (1 - Kilometer | 2 - Mile) ")
else:
length_type = raw_input(number1 + " ... (1 - Kilometers | 2 - Miles) ")
convert = raw_input("I want to convert into (1 - Kilometers | 2 - Miles): ")
if length_type == "1" and convert == "1":
print ""
print "^^^^^^^^^^^^^"
print "%s kilometer(s) = %s kilometer(s)" % (number1, number1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
elif length_type == "1" and convert == "2":
number2 = float(number1) * 0.62
print ""
print "^^^^^^^^^^^^^"
print "%s kilometer(s) = %s mile(s)" % (number1, number2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif length_type == "2" and convert == "1":
number2 = float(number1) / 0.62
print ""
print "^^^^^^^^^^^^^"
print "%s mile(s) = %s kilometer(s)" % (number1, number2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif length_type == "2" and convert == "2":
print ""
print "^^^^^^^^^^^^^"
print "%s mile(s) = %s mile(s)" % (number1, number1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
else:
print "Please try again."
print ""
length_converter()
else:
print "You need to enter a number."
print ""
length_converter()
def volume_converter():
number1 = raw_input("Enter your number: ")
if number1.replace(".", "", 1).isdigit() or number1.isdigit():
if number1 == "1":
volume_type = raw_input(number1 + " ... (1 - Liter | 2 - Gallon) ")
else:
volume_type = raw_input(number1 + " ... (1 - Liters | 2 - Gallons) ")
convert = raw_input("I want to convert into (1 - Liters | 2 - Gallons): ")
if volume_type == "1" and convert == "1":
print ""
print "^^^^^^^^^^^^^"
print "%s liter(s) = %s liter(s)" % (number1, number1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
elif volume_type == "1" and convert == "2":
number2 = float(number1) * 0.26417
print ""
print "^^^^^^^^^^^^^"
print "%s liter(s) = %s gallon(s)" % (number1, number2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif volume_type == "2" and convert == "1":
number2 = float(number1) / 0.26417
print ""
print "^^^^^^^^^^^^^"
print "%s gallon(s) = %s liter(s)" % (number1, number2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif volume_type == "2" and convert == "2":
print ""
print "^^^^^^^^^^^^^"
print "%s gallon(s) = %s gallon(s)" % (number1, number1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
else:
print "Please try again."
print ""
volume_converter()
else:
print "You need to enter a number."
print ""
volume_converter()
def try_again():
choice2 = raw_input("Would you like to convert again? (1 - Yes | 2 - No) ")
if choice2 == "1":
converter()
elif choice2 == "2":
print ""
print "Closing program ..."
else:
print "Please try again."
try_again()
def pretvornik():
izbira1 = raw_input("Kateri tip meritve želite izbrati? (1 - Dolžino | 2 - Količino) ")
if izbira1 == "1":
pretvornik_dolzine()
elif izbira1 == "2":
pretvornik_kolicine()
else:
print "Prosim, poskusite znova."
pretvornik()
poskusi_znova()
def pretvornik_dolzine():
stevilo1 = raw_input("Vpišite vaše število: ")
if stevilo1.replace(".", "", 1).isdigit() or stevilo1.isdigit():
if stevilo1 == "1":
tip_dolzine = raw_input(stevilo1 + " ... (1 - Kilometer | 2 - Milja) ")
elif stevilo1 == "2":
tip_dolzine = raw_input(stevilo1 + " ... (1 - Kilometra | 2 - Milji)")
elif 3 <= stevilo1 <= 4:
tip_dolzine = raw_input(stevilo1 + " ... (1 - Kilometri | 2 - Milje)")
else:
tip_dolzine = raw_input(stevilo1 + " ... (1 - Kilometrov | 2 - Milj) ")
pretvori = raw_input("Želim pretvoriti v (1 - Kilometre | 2 - Milje): ")
if tip_dolzine == "1" and pretvori == "1":
print ""
print "^^^^^^^^^^^^^"
print "%s kilometer(-ov) = %s kilometer(-ov)" % (stevilo1, stevilo1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
elif tip_dolzine == "1" and pretvori == "2":
stevilo2 = float(stevilo1) * 0.62
print ""
print "^^^^^^^^^^^^^"
print "%s kilometer(-ov) = %s milja(-lj)" % (stevilo1, stevilo2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif tip_dolzine == "2" and pretvori == "1":
stevilo2 = float(stevilo1) / 0.62
print ""
print "^^^^^^^^^^^^^"
print "%s milja(-lj) = %s kilometer(-ov)" % (stevilo1, stevilo2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif tip_dolzine == "2" and pretvori == "2":
print ""
print "^^^^^^^^^^^^^"
print "%s milja(-lj) = %s milja(-lj)" % (stevilo1, stevilo1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
else:
print "Prosim, poskusite znova."
print ""
pretvornik_dolzine()
else:
print "Vpisati morate številko."
print ""
pretvornik_dolzine()
def pretvornik_kolicine():
stevilo1 = raw_input("Vpišite vaše število: ")
if stevilo1.replace(".", "", 1).isdigit() or stevilo1.isdigit():
if stevilo1 == "1":
tip_kolicine = raw_input(stevilo1 + " ... (1 - Liter | 2 - Galona) ")
elif stevilo1 == "2":
tip_kolicine = raw_input(stevilo1 + " ... (1 - Litra | 2 - Galoni)")
elif 3 <= stevilo1 <= 4:
tip_kolicine = raw_input(stevilo1 + " ... (1 - Litri | 2 - Galone)")
else:
tip_kolicine = raw_input(stevilo1 + " ... (1 - Litrov | 2 - Galon) ")
pretvori = raw_input("Želim pretvoriti v (1 - Litre | 2 - Galone): ")
if tip_kolicine == "1" and pretvori == "1":
print ""
print "^^^^^^^^^^^^^"
print "%s liter(-ov) = %s liter(-ov)" % (stevilo1, stevilo1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
elif tip_kolicine == "1" and pretvori == "2":
stevilo2 = float(stevilo1) * 0.26417
print ""
print "^^^^^^^^^^^^^"
print "%s liter(-ov) = %s galona(-on)" % (stevilo1, stevilo2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif tip_kolicine == "2" and pretvori == "1":
stevilo2 = float(stevilo1) / 0.26417
print ""
print "^^^^^^^^^^^^^"
print "%s galona(-on) = %s liter(-ov)" % (stevilo1, stevilo2)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print ""
elif tip_kolicine == "2" and pretvori == "2":
print ""
print "^^^^^^^^^^^^^"
print "%s galona(-on) = %s galona(-on)" % (stevilo1, stevilo1)
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇ"
else:
print "Prosim, poskusite znova."
print ""
pretvornik_kolicine()
else:
print "Vpisati morate številko."
print ""
pretvornik_kolicine()
def poskusi_znova():
izbira2 = raw_input("Bi radi zopet pretvorili? (1 - Da | 2 - Ne) ")
if izbira2 == "1":
pretvornik()
elif izbira2 == "2":
print ""
print "Zapiram program ..."
else:
print "Prosim, poskusite znova."
poskusi_znova()
while True:
language = raw_input("Choose your language (1 - English | 2 - Slovenian): ").lower()
if language == "1" or language == "english":
print ""
print "UNIT CONVERTER"
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print "This program can convert between following units:"
print "LENGTH: - kilometers - miles"
print ""
print "VOLUME: - liters - gallons"
print ""
converter()
break
elif language == "2" or language == "slovenian":
print ""
print "PRETVORNIK ENOT"
print "ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ"
print "Ta program lahko pretvori naslednje enote:"
print "DOLŽINA: - kilometri - milje"
print ""
print "KOLIČINA: - litri - galone"
print ""
pretvornik()
break
else:
print "Please try again."
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment