本文介绍了诗词混音器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 作业要求注意:此程序需要打印输出并使用模块3中使用的代码语法:if,input,def,return,for / in keywords,.lower()和。 upper()方法,.append,.pop,.split方法,范围和len函数程序:poem mixer 此程序接受字符串输入,然后输出字符串$ b $的混合订单版本b 程序部分 程序流程收集单词列表,修改大小写和顺序,并打印 获取字符串输入,输入像诗,诗或说将字符串拆分为单个单词列表确定列表的长度按索引号和每个列表索引循环列表长度:如果单词是短(3个字母或更少)使列表中的单词小写如果一个单词很长(7个字母或更多)使列表中的单词大写用修改后的单词$ b调用word_mixer函数$ b打印word_mixer函数的返回值 word_mixer Functi on有1个参数:一个包含大于5个单词的字符串单词的原始列表,该函数返回一个新列表。 对原始列表进行排序创建一个新列表循环,同时列表长度超过5个单词:每个循环中的从排序的原始列表中弹出一个单词附加到新列表从列表末尾弹出单词5th并附加到新列表弹出列表中的第一个单词并附加到新列表弹出最后一个单词在列表中并附加到新列表在退出循环时返回新列表 TODO:将图像上传到blob 输入示例(William Blake诗的开头,The飞) 输入一句话或一首诗:小飞,你夏天的戏剧我没有思索的手已经消失了。我不是像你一样飞吗?或艺术不是你这样的男人? 输出示例 或BRUSHED你不是小我吗?夏天是你?像THOUGHTLESS玩我不是我的飞人我是 在创建新列表的函数的每个循环中的替代输出在列表中添加\ n 或者你的b 不是你的b 我?夏天是你? 喜欢THOUGHLESS玩ia而不是手一个我的 fly am man 我尝试了什么: def word_mixer(word_list): word_list_sorted = sorted(word_list) print(sorted_list:,word_list_sorted) new_list = [] while(len(word)> 5): #new_list.append(word_list_sorted。 pop()) new_list.append(word_list_sorted.pop(-5)) new_list.append(word_list_sorted.pop(0)) new_list.append(word_list_sorted.pop(-1)) )#new_list_sorted = sorted(new_list) #print(sorted new_list:,new_list_sorted) return(new_list) poem = input(输入一个诗:) word_list = poem.split() word_list_len = len(word_list)#word_list_len = len(word_list) #print(word_list_length:,word_list_len) new_list = [] word_mixer(word_list) print(new_list) #print(word_list:,word_list) 诗=输入(输入一首诗:) word_list = poem.split() word_list_len = len (word_list) for word_list: if len(word)< 6:x = word.lower() print(x) else:x = word.upper() print(x) sorted(word_list) print(word_list) print(word_list_len) 解决方案 我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。 亲自尝试,你可能会发现它不是和你想的一样困难! 如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不会为你做这一切! 只是发布你的作业问题,希望我们能为你做这些问题,不会让你到处找... WEATHER pthon编程 [ ^ ] 诗=输入(输入一句话或诗:) original_list = poem.split() new_list = [] new_poem = [] 对于original_list中的单词: if len(word)< 4: new_list.append(word.lower()) elif len(word)> 6: new_list.append(word.upper()) elif len(word)== 4或5或6: new_list.append(word) else:传递 def word_mixer(new_list): new_list.sort()而len(new_list)> 5: new_poem.append(new_list.pop(-5)) new_poem.append(new_list.pop(0)) new_poem.append(new_list.pop(-1)+' \ n') 加入=''。join(new_poem) print(已加入) word_mixer(new_list) Assignment RequirementsNOTE: This program requires print output and using code syntax used in module 3: if, input, def, return, for/in keywords, .lower() and .upper() method, .append, .pop, .split methods, range and len functionsProgram: poem mixerThis program takes string input and then prints out a mixed order version of the stringProgram Partsprogram flow gathers the word list, modifies the case and order, and printsget string input, input like a poem, verse or sayingsplit the string into a list of individual wordsdetermine the length of the listLoop the length of the list by index number and for each list index:if a word is short (3 letters or less) make the word in the list lowercaseif a word is long (7 letters or more) make the word in the list uppercasecall the word_mixer function with the modified listprint the return value from the word_mixer functionword_mixer Function has 1 argument: an original list of string words, containing greater than 5 words and the function returns a new list.sort the original listcreate a new listLoop while the list is longer than 5 words:in each loop pop a word from the sorted original list and append to the new listpop the word 5th from the end of the list and append to the new listpop the first word in the list and append to the new listpop the last word in the list and append to the new listreturn the new list on exiting the loopTODO: upload image to blobinput example (beginning of William Blake poem, "The Fly")enter a saying or poem: Little fly, Thy summer’s play My thoughtless hand Has brushed away. Am not I A fly like thee? Or art not thou A man like me?output exampleor BRUSHED thy not Little thou me? SUMMER’S thee? like THOUGHTLESS play i a not hand a my fly am manalternative output in each loop in the function that creates the new list add a "\n" to the list or BRUSHED thy not Little thou me? SUMMER’S thee? like THOUGHTLESS play i a not hand a my fly am manWhat I have tried:def word_mixer(word_list): word_list_sorted=sorted(word_list) print("sorted_list:",word_list_sorted) new_list=[] while(len(word)>5): #new_list.append(word_list_sorted.pop()) new_list.append(word_list_sorted.pop(-5)) new_list.append(word_list_sorted.pop(0)) new_list.append(word_list_sorted.pop(-1)) #new_list_sorted=sorted(new_list) #print("sorted new_list:",new_list_sorted) return(new_list)poem=input("Enter a poem:")word_list = poem.split()word_list_len=len(word_list)#word_list_len=len(word_list)#print("word_list_length:",word_list_len)new_list=[]word_mixer(word_list)print(new_list)#print("word_list:",word_list)poem=input("Enter a poem:")word_list = poem.split()word_list_len=len(word_list)for word in word_list: if len(word)<6: x=word.lower() print(x) else: x=word.upper() print(x)sorted(word_list)print(word_list)print(word_list_len) 解决方案 We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it is not as difficult as you think!If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!Just posting your homework questions in the hope we will do them for you is not going to get you anywhere ... The WEATHER pthon programming[^]poem = input("enter a saying or poem: ")original_list = poem.split()new_list =[]new_poem=[]for word in original_list: if len(word) < 4: new_list.append(word.lower()) elif len(word) > 6: new_list.append(word.upper()) elif len(word)== 4 or 5 or 6: new_list.append(word) else: passdef word_mixer(new_list): new_list.sort() while len(new_list) > 5: new_poem.append(new_list.pop(-5)) new_poem.append(new_list.pop(0)) new_poem.append(new_list.pop(-1)+'\n') joined = ' '.join(new_poem) print(joined)word_mixer(new_list) 这篇关于诗词混音器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!