Created
September 20, 2017 07:03
-
-
Save simform-solutions/75a6516f8732aef323a094d3a9336314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will ask the user to enter the amount and Units (Iota, MegaIota, GigaIota,etc.) | |
def transfer_value_user_input(): | |
print("\n\nEnter a number and the the unit size.\n" | |
"Avaliable units are \"i\"(Iota), \"ki\"(KiloIota), \"mi\"(MegaIota), " | |
"\"gi\"(GigaIota) and \"ti\"(TerraIota)\n" | |
"Example: If you enter \"12.3 gi\", I will send 12.3 GigaIota\n") | |
ask_user = True | |
while ask_user: | |
user_input = raw_input("Please enter the amount to send: ") | |
user_input = user_input.upper() | |
user_input_as_list = list(user_input) | |
allowed_characters = list("1234567890. IKMGT") | |
allowed_for_numbers = list("1234567890.") | |
allowed_for_units = list("iIkKmMgGtT") | |
is_valid = True | |
value = "" | |
unit = "" | |
i = 0 | |
while i < len(user_input_as_list): | |
char = user_input_as_list[i] | |
if char in allowed_characters: | |
if char in allowed_for_numbers: | |
value += char | |
elif char in allowed_for_units: | |
unit += char | |
else: | |
is_valid = False | |
i += 1 | |
if is_valid: | |
try: | |
value = float(value) | |
if unit == "I": | |
value = value | |
if 1 > value > 0: | |
print("You entered a amount greater then 0 but smaller then 1 Iota!\n" | |
"Can only send whole Iotas...\n ") | |
else: | |
return int(value) | |
elif unit == "KI": | |
value *= 1000 | |
if 1 > value > 0: | |
print("You entered a amount greater then 0 but smaller then 1 Iota!\n" | |
"Can only send whole Iotas...\n ") | |
else: | |
return int(value) | |
elif unit == "MI": | |
value *= 1000000 | |
if 1 > value > 0: | |
print("You entered a amount greater then 0 but smaller then 1 Iota!\n" | |
"Can only send whole Iotas...\n ") | |
else: | |
return int(value) | |
elif unit == "GI": | |
value *= 1000000000 | |
if 1 > value > 0: | |
print("You entered a amount greater then 0 but smaller then 1 Iota!\n" | |
"Can only send whole Iotas...\n ") | |
else: | |
return int(value) | |
elif unit == "TI": | |
value *= 1000000000000 | |
if 1 > value > 0: | |
print("You entered a amount greater then 0 but smaller then 1 Iota!\n" | |
"Can only send whole Iotas...\n ") | |
else: | |
return int(value) | |
else: | |
print("You didn't enter a valid unit size! Please try again\n") | |
except: | |
print("You didn't enter a valid value! Please try again\n") | |
else: | |
print("You didn't enter a valid value! Please try again\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment