【问题标题】:How To Add More Than one Value In Elif Python? [duplicate]如何在 Elif Python 中添加多个值? [复制]
【发布时间】:2020-05-01 15:51:17
【问题描述】:

我是 Python 新手,我想知道如何在 == 之后添加多个值?

代码如下:

gender = input('Are You Male Or Female ? ')

if gender.capitalize() == 'Male':
    print('You Got 10000 Rs')

elif gender.capitalize() == 'Female':
    print('You Got 5000 Rs')

else:
    print('You Got 1000 Rs')

如您所见,elif== 之后有'Female'。如果我想在'Female' 之后添加另一个值怎么办?

【问题讨论】:

  • 查找“和”和“或”。
  • @SayandipDutta,你误会了capitalize()upper()capitalize() 仅将第一个字符设置为大写。
  • @SayanipDutta 不,capitalize() 只会将第一个字母转换为大写字母。
  • 哦,是的,我的错。

标签: python


【解决方案1】:

你可以使用or关键字。

    gender = input('Are You Male Or Female ? ')

    if gender.capitalize() == 'Male':
        print('You Got 10000 Rs')

    elif gender.capitalize() == 'Female' or gender.capitalize() == 'Others':
        print('You Got 5000 Rs')

    else:
        print('You Got 1000 Rs')

输出:

    Are You Male Or Female ? Others
    You Got 5000 Rs

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 2021-11-18
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    相关资源
    最近更新 更多