Python 程式檢查一個字串是否迴文
給定一個字串,我們的任務就是檢查這個字串是否迴文。
演算法
Step1: Enter string as an input. Step2: Using string slicing we reverse the string and compare it back to the original string. Step3: Then display the result.
示例程式碼
my_string=input("Enter string:")
if(my_string==my_string[::-1]):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")輸出
Enter string:madam The string is a palindrome Enter string:python The string isn't a palindrome
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP