"""
This program presents a menu to the user and based upon the selection made
invokes already existing programs respectively.
"""
import sys
def get_numbers():
"""get the upper limit of numbers the user wishes to input"""
limit = int(raw_input('Enter the upper limit: '))
numbers = []
# obtain the numbers from user and add them to list
counter = 1
while counter <= limit:
numbers.append(int(raw_input('Enter number %d: ' % (counter))))
counter += 1
return numbers
def main():
continue_loop = True
while continue_loop:
# display a menu for the user to choose
print('1.Sum of numbers')
print('2.Get average of numbers')
print('X-quit')
choice = raw_input('Choose between the following options:')
# if choice made is to quit the application then do the same
if choice == 'x' or 'X':
continue_loop = False
sys.exit(0)
"""elif choice == '1':
# invoke module to perform 'sum' and display it
numbers = get_numbers()
continue_loop = False
print 'Ready to perform sum!'
elif choice == '2':
# invoke module to perform 'average' and display it
numbers = get_numbers()
continue_loop = False
print 'Ready to perform average!'"""
else:
continue_loop = False
print 'Invalid choice!'
if __name__ == '__main__':
main()
只有当我输入“x”或“X”作为输入时,我的程序才会处理。对于其他输入,程序将退出。我已经注释掉了 elif 部分,并且只使用了 if 和 else 子句。现在抛出语法错误。我究竟做错了什么?