python - 对于这段读取它是否为回文的代码,我想用 for 循环替换 [::-1] 并获得相同的功能
问题描述
string = (input("Input your own string: "))
string = string.lower()
if string == string[::-1]:
print("This is a Palindrome")
else:
print("This is not a Palindrome")
我想用 for 循环替换 [::-1] 并获得相同的功能
解决方案
老实说,我不知道你的真正意思或你的目标是什么,但你可以做类似的事情
for i in range(amount):
string = (input("Input your own string: "))
string = string.lower()
if string == string[::-1]:
print("This is a Palindrome")
else:
print("This is not a Palindrome")
或者
run = True
while run == True:
string = (input("Input your own string: "))
string = string.lower()
if string == string[::-1]:
print("This is a Palindrome")
else:
print("This is not a Palindrome")
推荐阅读
- python - 使用 Styler (pandas) 为数据框着色后格式化数字
- coq - 编译多个 Coq 文件不起作用
- ios - 关闭颜色选择器视图后的整个视图块
- java - 为什么从 ArrayAdapter 中的 ListView 获取项目时会出错?
- oracle - 当一个表在 Oracle 中有这么多索引时,如何提高插入的性能?
- php - 如何使用引导程序为每个 foreach 制作一列?
- reactjs - 执行 axios 请求的自定义钩子 [React, Typescript]
- javascript - 在 setAttribute() 中使用变量
- azure - 将平面文件从本地目录上传到 Azure 文件共享
- javascript - 有没有办法在调试控制台中调用导入的函数?