第30讲动动手
大神们,这道题我大概的思路是:将每个单词对应的行数都写出来,最后得到一组1111111111121223111213222 长度为25的字符串,然后将每个单词的长度的字符串截取出来去跟第一个比,如果中间出现任何不一样的就break,然后判断下一个单词。。。但是,我看了半天,,应该是最后的标记的地方有点点问题,,但是看了半天不知道是哪有问题 ,还请大神们帮忙看看
'''美式键盘'''
words = ["Twitter", "TOTO", "FishC", "Python", "ASL"]
leng_ =[]
l1 = 'qwertyuiop'
l2 = 'asdfghjkl'
l3 = 'zxcvbnm'
last = ''#每个单词对应的计算机行数
answer = []
for word in words:
word = str(word)
for i in word.casefold():
if i in l1:
last = ''.join((last,('1')))
elif i in l2:
last = ''.join((last,('2')))
elif i in l3:
last = ''.join((last,('3')))
#找出每个单词对应的长度
for i in words:
leng = len(i)
leng_.append(leng)
flag = 0
for y in leng_:
word_ = last[:y]
last = last.removeprefix(word_)
print(y,len(last))
for j in range(len(word_)):
print(word_)
major = word_
'''美式键盘'''
words = ["Twitter", "TOTO", "FishC", "Python", "ASL"]
leng_ =[]
l1 = 'qwertyuiop'
l2 = 'asdfghjkl'
l3 = 'zxcvbnm'
last = ''#每个单词对应的计算机行数
answer = []
for word in words:
word = str(word)
for i in word.casefold():
if i in l1:
last = ''.join((last,('1')))
elif i in l2:
last = ''.join((last,('2')))
elif i in l3:
last = ''.join((last,('3')))
#找出每个单词对应的长度
for i in words:
leng = len(i)
leng_.append(leng)
flag = 0
for y in leng_:
word_ = last[:y]
last = last.removeprefix(word_)
print(y,len(last))
for j in range(len(word_)):
print(word_)
major = word_
if major != word:
flag = 1
break
else:
continue
if flag == 0:
answer.append(words)
print(answer) 有那么复杂吗?咋让你搞得这么多
def isSameLine(word):
l1 = 'qwertyuiop'
l2 = 'asdfghjkl'
l3 = 'zxcvbnm'
if all():
return True
if all():
return True
if all():
return True
else:
return False
if __name__ == '__main__':
words = ["Twitter", "TOTO", "FishC", "Python", "ASL"]
for w in words:
if isSameLine(w):
print(w) 本帖最后由 傻眼貓咪 于 2022-4-1 14:07 编辑
keyboard = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
words = ["Twitter", "TOTO", "FishC", "Python", "ASL"]
answer = lambda words:
print(answer(words)) qq1151985918 发表于 2022-4-1 00:27
有那么复杂吗?咋让你搞得这么多
def isSameLine(word):
高手, 二楼是高手,但是感觉已经超纲了,我的解答如下:
tex1=input('请输入需要签定的词汇(用空格分开)')
tex2=tex1.casefold()
tex=tex2.split()
ans=[]
one="qwertyuiop"
two="asdfghjkl"
three="zxcvbnm"
n=0
for i in tex:
for j in i:
if j in one:
n+=1
if n>=len(i):
ans.append(i)
n=0
break
else:
n=0
break
n=0
for i in tex:
for j in i:
if j in two:
n+=1
if n>=len(i):
ans.append(i)
n=0
break
else:
n=0
break
n=0
for i in tex:
for j in i:
if j in three:
n+=1
if n>=len(i):
ans.append(i)
n=0
break
else:
n=0
break
print(ans) qq1151985918 发表于 2022-4-1 00:27
有那么复杂吗?咋让你搞得这么多
def isSameLine(word):
是的是的。。。但是我下面这些还没学到 不太明白是什么意思
if __name__ == '__main__':
words = ["Twitter", "TOTO", "FishC", "Python", "ASL"]
for w in words:
if isSameLine(w):
print(w) Victor0321 发表于 2022-4-4 16:44
是的是的。。。但是我下面这些还没学到 不太明白是什么意思
if __name__ == '__main__':
https://blog.csdn.net/weixin_51171020/article/details/121263235
页:
[1]