Выполнение попытки и исключения на выходеPython

Программы на Python
Ответить
Anonymous
 Выполнение попытки и исключения на выходе

Сообщение Anonymous »

У меня возникла проблема с программой, в которой она запускает исключение вместе с командой try, и я не знаю, что делать, поскольку она печатает преобразование и сообщение об ошибке.

Код: Выделить всё

def main():
print('What would you like to convert?')
print('1. Miles to Kilometers')
print('2. Fahrenheit to Celcius')
print('3. Gallons to Liters')
print('4. Pounds to Kilograms')
print('5. Inches to Centimeters')
try:
option = int(input('Menu Option:'))
if option == 1:
Inptmiles = float(input('Enter number of miles to convert:'))
milestokm(Inptmiles)
usercontinue()
if option == 2:
InptFrnht = float(input('Enter degrees that you would like to convert:'))
FrnhttoClcs(InptFrnht)
usercontinue()
if option == 3:
InptGllns = float(input('Enter number of Gallons you would like to convert:'))
GllnstoLtrs(InptGlls)
usercontinue()
if option == 4:
InptLbs = float(input('Enter number of pounds you would like to convert:'))
LbstoKgs(InptLbs)
usercontinue()
if option == 5:
InptInches = float(input('Enter number of Inches you would like to convert:'))
InchestoCm(InptInches)
usercontinue()
except:
print('Sorry there was an error with your input')
def milestokm(miles):
convkm = miles * 1.6
print(f'{miles} Miles is equal to {convkm:.2f} Kilometers')
def FrnhttoClcs(Fahrenheit):
convClcs = (Fahrenheit - 32) * 5/9
print(f'{Fahrenheit} Degrees Fahrenheit is equal to {convClcs:.2f} Degrees Celcius')
def GllnstoLtrs(Gallons):
convLtrs = Gallons * 3.9
print(f'{Gallons} Gallons is equal to {convLtrs:.2f} Liters')
def LbstoKgs(Pounds):
convKgs = Pounds * 0.45
print(f'{Pounds} Pounds is equal to {convKgs:.2f} Kilograms')
def InchestoCm(Inches):
convCm = Inches * 2.54
print(f'{Inches} Inches is equal to {convCm:.2f} Centimeters')

main()
Я попытался переместить исключение за пределы команд определения, которые использовали сохраненные переменные, но это вернулось как ошибка.

Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-output
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»