1. Palindromes (e.g. racecar) : a word that is the same backwards and forwards
2. isPal(x): Input: list; output: True or False, depending on whether x is a palindrome
3. isPalN(n, 1st): Input: interger, list; output: print"Is a pllindrome" or "Is not a palindrome", depending on whether the first n elements of 1st form a palindrome.
4. your task: come up with possible inputs to "isPal" and what is should output in each case; come up with possilble inputs to the function "isPalN" and what is should output in each case
def reverse_list(x): #reverse list#
return x[::-1]
def reverse(x): #判断是否是Palindromes#
temp=x
lst = reverse_list(temp)
print(lst)
if lst == x:
return True
else:
return False
def is_reverse(n,lt):
new_list = []
for i in range(n):
new_list.append(lt[i])
if reverse(new_list):
print('Is a palindrome')
else:
print('Is not a palindrome')
"""(把x装进list)
x='abcde'
list(x)
(reverse a string表达):
x = 'abcd'
c = x[::-1]
print(c) --- dcba
(x='1234' --- 4321 只能string不能转换int, int 要用列表)
""
int 装进list表达 列表前几位装进新列表
x = [1,2,3,4]
list = []
for i in range(2):
print (x[i]) # 取x前两位数1,2 #
list.append(x[i]) # 把x[i]中的两位数装进list里面生成新list #
print (list)