我正在做一个学校项目。 我对如何使 ( if ) 语句检测大小写字符感到困惑。 我曾尝试在 if 语句中使用“and”,但它会太长。 我当前的输入是:
a=input('Line: ')
if 'robot' in a:
print('There is a small robot in the line.')
elif ('robot'.upper()) in a:
print('There is a big robot in the line.')
elif b in a:
print('There is a medium robot in the line.')
else:
print('No robots here.')
别介意 (b) 我只是想弄清楚一些我不知道如何解释的事情。 我正在寻找的输出示例如下:
There is a "robot" in the line
then it would print
'There is a robot in the line'
程序将检查大写和小写字符。 如果一个输入全部大写,它会打印出来 队伍里有一个大机器人 如果输入只有小写字母,那么它只会打印 队伍中有一个小机器人。 如果输入同时包含小写和大写,它将打印: 生产线上有一台中型机器人。
请您参考如下方法:
在检查小写的 robot 是否在输入字符串中之前,您可以先将输入小写:
改变:
elif b in a:
到:
elif 'robot' in a.lower():
