Skip to main content
 首页 » 编程设计

python之翻译伪代码回文

2025年04月02日16over140

<分区>

我有需要翻译的伪代码:

Prompt the user to enter a string and call it s. 
Let l be the length of string 
For i from 0 upto l-1: 
    print s[0:i] 
For i from 0 upto l-1: 
    print s[i:l] 
Print a closing statement 

这是我的翻译:

 def main(): 
 
        s=(input("Please enter a string: ")) 
        L=len(s) 
 
        for i in [0,L-1]: 
            print (s[0:i]) 
 
        for i in [0,L-1]: 
            print(s[i:L]) 
 
        print("This program is complete!") 
 
    main() 

但是,代码打印不正确。有人可以帮我找到我的错误吗?谢谢。