Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added palindrome.py #119

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Code/palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 31 17:23:49 2017

@author: cam-barts
"""
import argparse
# Using argparse, which is a argument parsing module from the standard library, to take input from the user
# https://docs.python.org/2/library/argparse.html
parser = argparse.ArgumentParser()

# Create an agrument, named 'String' and will be accessed as args.String. It will be of string type, and the help block with say "String to check palindrome-ness"
# $python palindrome.py -h
# usage: palindrome.py [-h] <string>
#
# positional arguments:
# <sring> String to check palindrome-ness
parser.add_argument("String", type=str, help= "String to check palindrome-ness")
args = parser.parse_args()
String = args.String

# Adding [::-1] reverses a string in python2
StringReverse = String[::-1]

if __name__ == '__main__':
if str(String) == str(StringReverse):
print "String is a palindrome!"
else:
print "String is not a palindrome!"