我需要创建一个程序,要求用户输入一个字符串,然后选择以下txt编辑器之一应用于它:
(lcase) make each letter lowercase
(ucase) make each letter uppercase
(alt) make each letter alternate in case, with first letter capitalized
(remspace) remove all white space
(1337) convert to l337-speak
(rev) reverse the string
(new) enter a new string
(restore) replace string with last one entered
(quit) exit the program
程序需要在循环中运行,直到用户输入quit。你知道吗
到目前为止,这是我的代码,但它并没有真正起作用(提示工作得很好,但我无法让修饰符工作):
print "Welcome to the text converter. Your options are to:"
print "(lcase) make each letter lowercase"
print "(ucase) make each letter uppercase"
print "(alt) make each letter alternate in case, with first letter capitalized"
print "(remspace) remove all white space"
print "(1337) convert to l337-speak"
print "(rev) reverse the string"
print "(new) enter a new string"
print "(restore) replace string with last one entered"
print "(quit) exit the program"
print "-----------------------------------------------"
y = raw_input("Please enter a string: ")
def reverse_string(y):
return y[:: -1]
x = raw_input("Action (lcase, ucase, alt, remspace, rev, new, restore, quit):")
while x == raw_input:
if x == "lcase":
return str.lower(y)
if x == "ucase":
return y.upper(y)
if x == "alt":
return
if x == "remspace":
return str.string(y)
if x == "rev":
return
if x == "restore":
return y
if x == "quit":
print "See you next time!"
exit()
if x == "new":
break
return raw_input()
请帮我修改代码。你知道吗
while x == raw_input
将永远无法到达。return
应该在函数内部。你知道吗相关问题 更多 >
编程相关推荐