프로그램을 실행하고 값 3, 1, 1을 넣으면 한 컵을 스푼으로 변환 할 때, 그것은 하단에있는 TOtbsp 함수를 사용합니다. 문제 해결을 위해 최종 결과가 나오기 전에 4 가지 변수를 출력하도록했습니다.사전 값 (정수)으로 정수를 곱하려고하면 아무런 의미가없는 답을줍니다.
은에 컵을 변환 : 이러한 변수는 모든 즉, 무엇을 제공하는 것은 이것을 TOtbsp 기능입니다 있어요 ^, 올바른 결과에서
def TOtbsp():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: tablespoons')
dictEnt = dCallOne['tbsp']
print (dCallOne['tbsp'])
print (dCallOne)
print (dictEnt)
print (convFactor)
calc = convFactor * dictEnt
print(calc)
를 인쇄 큰술
16
{'tbsp': 16, 'tsp': 48, 'quart': 0.25, 'floz': 8.32674, 'pint':0.5,'gal':0.0625, 'ml': 236.588, 'liter': 0.236588}
16
1
1111111111111111
이들은 제외한 모든 올바른지 마지막 하나, calc
. 내가 아는 한
calc = convFactor * dictEnt
calc = (convFactor * dictEnt)
calc = (convFactor * dCallOne['tbsp'])
calc = (convFactor * (dCallOne['tbsp'])
(convFactor * dictEnt) = calc
(convFactor * (dCallOne['tbsp']) = calc
convFactor * dictEnt = calc
(convFactor * dCallOne['tbsp']) = calc
,이 모두가, 어쩌면 바닥 네, excapt 모두 convFactor
, dictEnt
및 dCallOne
모두 얻을 수 있기 때문에 정확한 답변을 얻을해야한다 : 나는 몇 가지 다른 방법으로 그것을 설정 시도했습니다 정수.
전체 코드는 다음과 같습니다.
import os
tbsp = {'tbsp' : 1 ,
'cup' : 0.0625 ,
'tsp' : 3 ,
'quart' : 0.015625 ,
'floz' : 0.5 ,
'pint' : 0.03125 ,
'gal' : 0.00390625 ,
'ml' : 14.7868 ,
'liter' : 0.0147868}
tsp = {'cup' : 0.0208333 , 'tbsp' : 0.333333 , 'quart' : 0.0052083333 , 'floz' : 0.1666666667 , 'pint' : 0.0104166667, 'gal' : 0.00130208323 , 'ml' : 4.92892 , 'liter' : 0.00492892}
dictcups = cups = {'tbsp' : 16 ,
'tsp' : 48 ,
'quart' : 0.25 ,
'floz' : 8.32674 ,
'pint' : 0.5 ,
'gal' : 0.0625 ,
'ml' : 236.588 ,
'liter' : 0.236588}
quart = {'cup' : 4 , 'tsp' : 192 , 'tbsp' : 64 , 'floz' : 32 , 'pint' : 2 , 'gal' : 0.25 , 'ml' : 946.353 , 'liter' : 0.946353}
floz = {'cup' : 0.125 , 'tsp' : 6 , 'quart' : 0.03125 , 'tbsp' : 2 , 'pint' : 0.0625 , 'gal' : 0.0078125 , 'ml' : 29.5735 , 'liter' : 0.0295735}
pint = {'cup' : 2 , 'tsp' : 96 , 'quart' : 0.5 , 'floz' : 16 , 'tbsp' : 32 , 'gal' : 0.125 , 'ml' : 473.176 , 'liter' : 0.473176}
gal = {'cup' : 16 , 'tsp' : 768 , 'quart' : 4 , 'floz' : 128 , 'pint' : 8 , 'tbsp' : 256 , 'ml' : 3785.41 , 'liter' : 3.78541}
ml = {'cup' : 0.0042267571 , 'tsp' : 0.202884 , 'quart' : 0.00105669 , 'floz' : 0.033814 , 'pint' : 0.00211338 , 'gal' : 0.000264172 , 'tbsp' : 0.067628 , 'liter' : 0.001}
liter = {'cup' : 4.226757063 , 'tsp' : 202.884 , 'quart' : 1.05669 , 'floz' : 33.814 , 'pint' : 2.11338 , 'gal' : 0.264172 , 'ml' : 1000 , 'tbsp' : 67.628}
acceptableInputs = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] #This is used to check if what the user entered is one of the eight acceptable units
def takeUnit1(): #Figure out what unit the user wants to convert
global convFactor
print ('Unit Converter')
print ('')
print ('')
print ('Select the unit you want to convert FROM')
print ('')
print ('1 Tbsp - Tablespoon')
print ('2 Tsp - Teaspoon')
print ('3 C - Cups')
print ('4 qt. - Quart')
print ('5 fl. oz. - Fluid Ounce')
print ('6 gal. - Gallon')
print ('7 ml - Milliliter')
print ('8 L - Liter')
print ('9 P - Pints')
convFROM = input('Unit: ')
convFactor = input('How many?: ')
if convFROM in acceptableInputs: #Check if input is acceptable
global convFROMconv
global dCallOne
if convFROM == '1':
convFROMconv = 'Tablespoons'
dCallOne = tbsp
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '2':
convFROMconv = 'Teaspoons'
dCallOne = tsp
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '3':
convFROMconv = 'Cups'
dCallOne = dictcups
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '4':
convFROMconv = 'Quarts'
dCallOne = quart
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '5':
convFROMconv = 'Fluid Ounces'
dCallOne = floz
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '6':
convFROMconv = 'Gallons'
dCallOne = gal
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '7':
convFROMconv = 'Milliliters'
dCallOne = ml
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '8':
convFROMconv = 'Liters'
dCallOne = liter
takeUnit2() # Run the function to figure out what unit to convert to
elif convFROM == '9':
convFROMconv = 'Pints'
dCallOne = pint
takeUnit2() # Run the function to figure out what unit to convert to
else:
print ('')
else:
print('That is not an acceptable input, please try again')
def takeUnit2(): #This function is to figure out what unit the user wants to convert TO
os.system('cls')
print ('Select the unit you want to convert TO')
print ('1 Tbsp - Tablespoon')
print ('2 Tsp - Teaspoon')
print ('3 C - Cups')
print ('4 qt. - Quart')
print ('5 fl. oz. - Fluid Ounce')
print ('6 gal. - Gallon')
print ('7 ml - Milliliter')
print ('8 L - Liter')
print ('9 P - Pints')
convTO = input('Unit: ')
if convTO in acceptableInputs: #Checking if it is one of the 8 accepted units
global convTOname #Making convTOconv global
global TOfunc1
if convTO == '1': #This whole statement converts the input number to its corresponding name
convTOname = 'tbsp'
TOfunc1 = 'TOtbsp'
TOtbsp()
elif convTO == '2':
convTOname = 'tsp'
TOfunc1 = 'TOtsp'
TOtsp()
elif convTO == '3':
convTOname = 'cup'
TOfunc1 = 'TOcups'
TOcup()
elif convTO == '4':
convTOname = 'quart'
TOfunc1 = 'TOquarts'
TOquart()
elif convTO == '5':
convTOname = 'floz'
TOfunc1 = 'TOfloz'
TOfloz()
elif convTO == '6':
convTOname = 'gal'
TOfunc1 = 'TOgal'
TOgal()
elif convTO == '7':
convTOname = 'ml'
TOfunc1 = 'TOml'
TOml()
elif convTO == '8':
convTOname = 'liter'
TOfunc1 = 'TOliters'
TOliter()
elif convTO == '9':
convTOname = 'pint'
TOfunc1 = 'TOpint'
TOpint()
else: #Statement requires an else, not intended to ever be used
print ('')
else:
print('That is not an acceptable input, please try again')
def TOtbsp():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: tablespoons')
dictEnt = dCallOne['tbsp']
print (dCallOne['tbsp'])
print (dCallOne)
print (dictEnt)
print (convFactor)
calc = convFactor * dictEnt
print(calc)
def TOtsp():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: teaspoons')
print (dCallOne)
calc = dCallOne['tsp']
print(calc)
def TOcup():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: cups')
print (dCallOne)
calc = dCallOne['cup']
print(calc)
def TOquart():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: quarts')
print (dCallOne)
calc = dCallOne['quart']
print(calc)
def TOfloz():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: fluid ounces')
print (dCallOne)
calc = dCallOne['floz']
print(calc)
def TOml():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: milliliters')
print (dCallOne)
calc = dCallOne['ml']
print(calc)
def TOgal():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: gallons')
print (dCallOne)
calc = dCallOne['gal']
print(calc)
def TOpint():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: pints')
print (dCallOne)
calc = dCallOne['pint']
print(calc)
def TOliter():
os.system('cls')
print ('Convert ' + convFROMconv + ' to: liters')
print (dCallOne)
calc = dCallOne['liter']
print(calc)
takeUnit1()
불분명. "이것들은 모두 정확합니다, 마지막 것을 제외하고는"- 정확하지 않은 것은 정확히 무엇입니까? "(이유 삽입) 1234를 얻을 것으로 예상했지만 대신 4567을 얻었습니다."라고 말합니다. – Brandin