pythonifelse用法_python ifelifelse用法和说明

"""

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值