我正在尝试创建一个程序来使用python的一些字符串操作功能。我做了一些函数,成功地操纵了字符串。我遇到的困难是如何创建一个按顺序运行所有其他函数的主函数。这是我到目前为止的代码
def main():
print("This program demonstrates Python's String manipulation ability")
s=input("Enter a String: ")
def change(s):
firstchar=s[0]
modifieds=s[1:].replace(firstchar.lower(),"$")
modifieds=modifieds.replace(firstchar.upper(),"$")
final=(firstchar+modifieds)
print(final)
def reverse(s):
res=""
for i in range(len(s)):
if i%2==0:
res+=(s[i].lower())
else:
res+=(s[i].upper())
return res[::-1]
def code(s):
string=s.upper()
n=len(string.split(" "))
print()
output=""
for i in string:
output+=chr(ord(i)+n)
print(output)
main()
给你:
对pycodestyle/pep8代码没有影响。我重命名了reverse函数,以免与内置的reverse()方法混淆
我不确定你的目标到底是什么,但这里是它的输出:
如果我没说错的话,你们的反向函数缩进是无效的
相关问题 更多 >
编程相关推荐