【发布时间】:2018-08-17 03:07:38
【问题描述】:
我在做一个学校项目。 我对如何使 ( 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
标签: python