Python 如何检查输入后是否使用了字母?
我应该写一个程序,要求用户输入一个有5个字母的单词,然后检查第三个字母是否是ePython 如何检查输入后是否使用了字母?,python,jupyter-notebook,Python,Jupyter Notebook,我应该写一个程序,要求用户输入一个有5个字母的单词,然后检查第三个字母是否是e input('Enter word with 5 letters:' if [2] == e: print("the third letter is e") 但是当我输入一个有5个字母的单词后,什么也没有发生 更正后的代码应如下所示: word = input('Enter word with 5 letters: ') if word[2] == 'e': print(&qu
input('Enter word with 5 letters:'
if [2] == e:
print("the third letter is e")
但是当我输入一个有5个字母的单词后,什么也没有发生
更正后的代码应如下所示:
word = input('Enter word with 5 letters: ')
if word[2] == 'e':
print("the third letter is e")
试试这个
user_input = input('Enter word with 5 letters:')
if user_input[2] == 'e':
print("the third letter is e")
您需要将值(在本例中为输入)保存到变量中,然后使用[]访问其字母
userInput = input('Enter word with 5 letters: ')
if userInput[2] == 'e':
print("the third letter is e")
如果要进一步使用或修改值、信息和操作,必须将它们保存到变量中。在Python中,可以读取数组之类的字符串。 例如:
myString = "abcdef"
print(myString[3])
你的成绩将被扣掉
所以你要做的是
首先,获取输入并将其保存到如下变量中
string_input = input()
第二次检查第三个字母是否为“e”
if(string_input[2]=='e'):
print("Third letter is e")
注意:string[]返回char value这甚至不是有效的代码。只需提出一个简短的问题,希望能说明一些您似乎没有解决的问题-您如何知道这个单词是不是五个字母?