美文网首页
2018-10-31

2018-10-31

作者: 自语自乐 | 来源:发表于2018-11-01 00:12 被阅读0次

    Python交互式程序与While循环

    (1)用户输入——input()

    message=input('show me a number and I will tell you if it is an odd number: ')

    number=int(message)

    if number % 2==0:

        print(str(number)+' is not an odd number!')

    else:

        print(str(number)+' is an odd number!')

    (2)While循环

    msg='please enter what you want to eat: '

    msg+='\n(enter "quit"when you have finished)'

    active=True

    food=[]

    while active:

        information=input(msg)

        if information!='quit':

            food.append(information)

        else:

            active=False

    print('you have ordered the following items:')

    for f in food:

        print(f)

    (3)break语句

    msg='please enter what you want to eat: '

    msg+='\n(enter "quit"when you have finished)'

    food=[]

    while True:

        information=input(msg)

        if information!='quit':

            food.append(information)

        else:

            break

    print('you have ordered the following items:')

    for f in food:

        print(f)

    (4)continue语句

    digits=range(10)

    for d in digits:

        if d %2 ==0:

            continue

        print(d)

    相关文章

      网友评论

          本文标题:2018-10-31

          本文链接:https://www.haomeiwen.com/subject/peaztqtx.html