![](/img/trans.png)
[英]How can you generate a list containing a mix of consecutive numbers and letters?
[英]Python how can you check for consecutive letters in a user input?
每當出現一組3個連續字符(根據qwerty鍵盤)時,如何檢查python中的用戶輸入。 它也應該不區分大小寫。
例如: asDFg
應該具有三組( asD
, sDF
和DFg
),並且DFg
應從得分中減去1分。
使用三個字符串ab和c表示qwerty鍵盤中的每一行,並在轉換為小寫字母時檢查子字符串
a="qwertyuiop"
b="asdfghjkl"
c="zxcvbnm"
str=raw_input()
score=0
for i in range(0,len(str)-2):
t=str[i:i+3]
if t.lower() in a or t.lower() in b or t.lower() in c :
score+=1
else:
score-=1
print score
輸入
asDFg
輸出
3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.