程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python computer level II problem, hope to solve

編輯:Python

subject :
There are Chinese recombined sentences when learning Chinese , There are also recombined sentences in English , Define a function comb(sentence), Its function is to confuse words in an English sentence , And connect the disordered words with a space , Then the output . If the words in the sentence
Less than or equal to 2 One output : The word of the original sentence is less than or equal to 2 individual .( Note that all strings in the program use double quotation marks "" Express ) Please put the number (1)~(7) And the corresponding underline are deleted , Fill in the blanks to complete the statements in the program , You cannot modify existing code .
import random
def comb(sentence): # Define a function , Parameter is sentence
words=(1)() #1 Separate the words
print("-"*60)
if len(words)==1 (2) len(words)==2: #2 If the word in the sentence is less than 2 individual , Do not disturb , Output "
The word of the original sentence is less than or equal to 2 individual "
print(" The word of the original sentence is less than or equal to 2 individual ")
else:
jumble=[]
while (3): #3 Make a mess of the words in the sentence
site = (4)(len(words)) #4
jumble.
(5)__ #5
words=_(6) #6 When slicing, use parentheses if the position is an expression () Cover up
s=(7)(jumble) #7 Join the words with a space
print(" The word combination after the sentence is out of order is :\n",s)
if name=="main":
txt="The Beijing Organising Committee for the 2022 Olympic and Paralympic Winter Games is a public institution with legal person status"
print(" The original sentence is :\n", txt)
comb(txt)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved