1
我試過看this,但無濟於事,繼承人我從鏈接中創建的代碼。嘗試查找字符串的大小時出錯
game = 1
while game == 1:
print('WORLD EVALUATOR 2000')
word = input("Insert some text...").lower()
words = word.split(" ")
lastWord = words[-1]
if word[0].lower() in 'aeiou':
print("The string begins with a vowel")
elif word[0].lower() in '1234567890':
print ("The string begins with a number")
elif word[0].lower() in 'bcdfghjklmnpqrstvwxyz':
print ("The string begins with a consonant")
elif word[0].lower() in '[email protected]#$%^&*()_+{}|:"<>?':
print ("The string begins with a symbol or a space.")
elif word[0].lower() in ' ':
print ("The string begins with a space.")
else:
print("The string does not begin with a vowel,number, consonant, space, or a symbol")
if word[1].lower() in 'aeiou':
print("The string's second letter is a vowel")
elif word[1].lower() in '1234567890':
print ("The string's second letter is a number")
elif word[1].lower() in 'bcdfghjklmnpqrstvwxyz':
print ("The string's second letter is a consonant")
elif word[1].lower() in '[email protected]#$%^&*()_+{}|:"<>?':
print ("The string's second letter is a symbol or a space.")
elif word[1].lower() in ' ':
print ("The string's second letter is a space.")
else:
print("The string's second letter is not a vowel,number, consonant, space, or a symbol")
if lastWord[-1].lower() in 'aeiou':
print("The string's last letter is a vowel")
elif lastWord[-1].lower() in '1234567890':
print("The string's last letter is a number")
elif lastWord[-1].lower() in 'bcdfghjklmnpqrstvwxyz':
print("The string's last letter is a consonant")
elif lastWord[-1].lower() in '[email protected]#$%^&*()_+{}|:"<>?':
print("The string's last letter is a symbol or a space.")
elif lastWord[-1].lower() in ' ':
print("The string's last letter is a space.")
else:
print("The string's last letter is not a vowel,number, consonant, or a symbol")
print("The string is " + str(len(words)) + ' letters/numbers/symbols long.')
接近尾聲是我用len的地方,但它不工作,我能有一些幫助嗎?
如果有人問,while循環沒有正確縮進,因爲在stackoverflow中的格式不喜歡我。實際上,循環對len部分的工作很好。
我得到的輸出,只是說,這是「1」 – CatsInSpace
WORLD EVALUATOR 2000 插入一些文字... Absosc 的字符串開頭元音 字符串的第二個字母是輔音 字符串的最後一個字母是輔音 該字符串是1個字母/數字/符號長。 – CatsInSpace
你正在計算的字數不是字母 –