我被要求创建3个函数来创建Vet Records。我必须使用2个函数分别验证Integer输入和String Input。我已经完成了大部分代码,但最后一部分在运行代码时没有打印出来。我的代码如下:
def getNewVetRecord():
getNewVetRecord=[]
return getNewvetRecord
def getValidInteger():
Ask_for_value = True
while(Ask_for_value == True):
try:
ID = int(input("Pet ID: "))
Ask_for_value = False
except ValueError:
print("Please enter a valid integer")
return ID
def getValidString():
Ask_for_value = False
Input_String = ("")
while(Ask_for_value == False):
Input_String = input("Pet Name: ")
Ask_for_value = Input_String.isalpha()
if(Ask_for_value == False):
print("Please enter a valid name")
return Input_String
def func():
stringValue = getValidString();
integerValue = getValidInteger();
species = input("species:")
ownername = input("owner first name:")
owner_last_name = input("owner last name:")
x=[]
x.append(stringValue)
x.append(integerValue)
x.append(species)
x.append(ownername)
x.append(owner_last_name)
return x
def main():
x=[]
x.append(func())
x.append(func())
x.append(func())
print( 'ID Pet Name Species\tOwner Name' )
print( '-- -------- -------\t----------' )
getVetRecord=[]
for x in getVetRecord:
for ind in x:
print(format(getVetRecord[1][ind], "3d"), format(getVetRecord[2][ind]+"", "11s"), format("", "1s"),\
format(getVetRecord[3][ind]+"", "10s"), format("", "2s"), getVetRecord[5][ind],',', getVetRecord[4][ind])
main()
它正确地执行了重要的部分,(验证和输入),但它没有打印答案。