Python:每日一题 80(答题领鱼币)
本帖最后由 新手·ing 于 2017-8-17 12:24 编辑题目:
写一个函数 reverse_string(string)
def reverse_string(string):
pass
该函数接收一个参数string
[*]string 为一个标准的英文句子
[*]要求返回string 中每一个单词颠倒后的句子
For example:
>>> reverse_string(This is an example!')
#'sihT si na !elpmaxe'
答案:
**** Hidden Message *****
sentense = 'This is an example!'
reverse_sentense = lambda s: ' '.join( for i in s.split()])
print(reverse_sentense(sentense)) 大...神...
吓的萌新一动不动{:10_245:} 新手·ing 发表于 2017-8-17 12:23
大...神...
吓的萌新一动不动
去做做精英挑战赛的题吧,http://bbs.fishc.com/thread-94648-1-1.html,特地为新手降低了难度,可以先从简单难度做起{:10_256:} sentence = input("please input a sentence:")
reverse_sentence=[]
for i in sentence.split():
reverse_sentence.append(i[::-1])
print(' '.join(reverse_sentence))
jerryxjr1220 发表于 2017-8-17 12:40
去做做精英挑战赛的题吧,http://bbs.fishc.com/thread-94648-1-1.html,特地为新手降低了难度,可以先从 ...
看了,但是不会啊,,,{:10_250:} def reverse_string(string):
list1=string.split(' ')
for i in list1:
print(i[::-1],end=' ') def reverse_string(string):
a = []
for i in string[::-1].split():
a.append(i)
cur = a[:]
for j in range(len(a)):
a = cur
print( ' '.join(a)) def reverse_string(string):
splitStrings = string.split()
i = 0
for splitString in splitStrings:
splitList = list(splitString)
splitList.reverse()
splitStrings = "".join(splitList)
i += 1
return " ".join(splitStrings) 不知道怎么写,尴尬 def reverse_string(words):
temp=words.split(" ")
#print(temp)
for each in temp:
print(each[::-1],end=" ")
reverse_string(input("请输入你要说的话:")) def reverse_string(string):
str0=string.split()
x=' '
for each in str0:
x+=' '+each[::-1]
return "'"+x.lstrip()+"'"
str0=input("请输入一个句子:")
print(reverse_string(str0))
运行结果:
============== RESTART: C:\Users\每日一题\80.py ==============
请输入一个句子:I am a Good Boy
'I ma a dooG yoB' {:10_312:}
def reverse_string(string):
return string[::-1].split()[::-1] 翻转,拆开,再翻转 九九八十一 发表于 2017-8-18 13:10
翻转,拆开,再翻转
思路正确,不过我们要求返回一个字符串~ def reverse_string(string):
string = string.split()
result = ''
for str in string:
result += str[::-1] + ' '
return result[:len(result)-2]
print(reverse_string('This is an example!'))
初学者,多谢指教。。。{:5_108:}
def reverse_string(string):
rev_string=[]
i = len(string)
while True:
if i != 0:
each = string
rev_string.append(each)
i -= 1
else:
break
for each in rev_string:
print (each,end="")
sentence = input("please input a sentence:")
reverse_string(sentence) def reverse_string(s):
return " ".join( for i in s.split()]) def reverse_string(str1):
reverse_str = ''
list1 = str1.split()
for i in range(len(list1)):
reverseTemp = list1[::-1]
list1 = reverseTemp
if i == 0:
reverse_str= list1
else:
reverse_str = reverse_str + " " + list1
return reverse_str
str1 = input('请输入一个标准的英文句子:')
reverse_str = reverse_string(str1)
print('单词颠倒后的句子:')
print(reverse_str)
=========== RESTART: D:/程序设计/Python 3.6/reverse_string_20170820.py ===========
请输入一个标准的英文句子:This is an example!
单词颠倒后的句子:
sihT si na !elpmaxe
def reverse_string(string):
pass
页:
[1]
2