-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.py
More file actions
33 lines (27 loc) · 990 Bytes
/
reverse.py
File metadata and controls
33 lines (27 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ********************************************************************************
# Author - Harshit Prasad
# 19.12.2016
# Python program : to reverse a string and check whether it's a palindrome or not.
# *********************************************************************************
# We will use - inbuilt functions like reversed() - which reverse each alphabet
# list() - which create the list of alphabets.
name = input('Enter your name!')
rev_name = reversed(name)
if list(name)==list(rev_name):
print('It is a palindrome.')
else:
print('It is not a palindrome.')
# It is for lower case letters only.
# Extras
# We can also write it as -
new_name = input('Enter your new name -')
if new_name == new_name[::-1]: # applicable for lower case letters only
print('It is a palindrome.')
else:
print('It is not a palindrome.')
# Extras again.
extra = 'Hello, My name is Python.'
len_of_extra = len(extra)
print(len_of_extra)
words = extra.count('name')
print(words)