这是代码 - 非常简单 - 但它给了我程序主要部分中的第一个异常 - 甚至没有要求用户输入我认为它应该在 - 在第一次输入时raw_input
- 我是一个初学者总体上很好地掌握语言 - 有什么想法吗?谢谢
import re,sys
#program to take details of people name, address and telephone number from user
#user must specify number of people first
class details:
def __init__(self,name=None,address=None,tel=None):
self.name=name
self.address=address
self.tel=tel
def changeAttribute(self,name=None,address=None,tel=None):
if name!=None:
self.name=name
if address!=None:
self.address=address
if tel!=None:
self.tel=tel
class main():
peopleList =[]
a=1
while a==1:
try:
numOfPeople = raw_input("enter number of people:")
if re.search('[^0-9\n]', numOfPeople):
raise Exception
except (Exception):
print ("illegal input ,must only be numbers - Please try again")
else:
numOfPeople=str(numOfPeople)
a=0
for i in range(0,numOfPeople):
x=1
while x==1:
try:
name=raw_input("Please enter name")
if re.search('[^a-zA-Z\n]',name):
raise Exception
except (Exception):
print("illegal name - Please use only letters")
else:
peopleList.extend(details(name))
x=0
x=1
while x==1:
try:
address=raw_input("Please enter address")
if re.search('[^a-zA-Z\n]',address):
raise Exception
except (Exception):
print("illegal name - Please use only letters")
else:
peopleList[-1].changeAttribute(None,address,None)
x=0
x=1
while x==1:
try:
tel=raw_input("Please enter telephone number")
if re.search('[^0-9]',tel):
raise Exception
except (Exception):
print("illegal name - Please use only numbers")
else:
peopleList[-1].changeAttribute(None,address,None)
x=0