诗词混音器程序 [英] Poem word mixer program

查看:84
本文介绍了诗词混音器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作业要求
注意:此程序需要打印输出并使用模块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





< b>我尝试了什么:



 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)

< b r />

诗=输入(输入一首诗:)


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 Requirements
NOTE: 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 functions
Program: poem mixer
This program takes string input and then prints out a mixed order version of the string

Program Parts

program flow gathers the word list, modifies the case and order, and prints

get string input, input like a poem, verse or saying
split the string into a list of individual words
determine the length of the list
Loop 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 lowercase
if a word is long (7 letters or more) make the word in the list uppercase
call the word_mixer function with the modified list
print the return value from the word_mixer function
word_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 list
create a new list
Loop while the list is longer than 5 words:
in each loop pop a word from the sorted original list and append to the new list
pop the word 5th from the end of the list and append to the new list
pop the first word in the list and append to the new list
pop the last word in the list and append to the new list
return the new list on exiting the loop
TODO: upload image to blob

input 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 example

or BRUSHED thy not Little thou me? SUMMER’S thee? like THOUGHTLESS play i a not hand a my fly am man

alternative 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 man



What 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:
        pass
def 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)


这篇关于诗词混音器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆