Skip to content

Commit 52cfe85

Browse files
Merge pull request geekcomputers#511 from nayaknameet/master
Fixes 3 files
2 parents d2def07 + 8803fe4 commit 52cfe85

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

Palindrome_Checker.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@
88

99
givenPhrase = input("\nPlease input a phrase:(Press ENTER to use the sample phrase) ")
1010

11-
if givenPhrase == "" or not givenPhrase.strip():
11+
if givenPhrase == "":
1212
print("\nThe sample phrase is: {0}".format(samplePhrase))
1313
phrase = samplePhrase
1414
else:
1515
phrase = givenPhrase
1616

17-
string = phrase.lower()
17+
phrase = phrase.lower()
1818

19-
if string == string[::-1]:
20-
print("\nWow!, The phrase is a Palindrome!")
21-
else:
22-
print("\nSorry, The given phrase is not a Palindrome.")
19+
20+
length_ = len(phrase)
21+
bol_ = True
22+
23+
# check using two pointers, one at beginning
24+
# other at the end. Use only half of the list.
25+
for items in range(length_//2):
26+
if phrase[items] != phrase[length_ - 1 - items]:
27+
print("\nSorry, The given phrase is not a Palindrome.")
28+
bol_ = False
29+
break
30+
31+
if bol_:
32+
print("\nWow!, The phrase is a Palindrome!")

Print_List_of_Even_Numbers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# INPUT NUMBER OF EVEN NUMBERS
2+
def print_error_messages():
3+
print("Invalid number, please enter a Non-negative number!")
4+
exit()
5+
6+
7+
try:
8+
n=int(input('Amount: '))
9+
except ValueError:
10+
print_error_messages()
211

3-
n=int(input('Amount: '))
412
start=0
513

14+
if n < 0:
15+
print_error_messages()
16+
617
for i in range(n):
718
print(start)
819
start+=2

Print_List_of_Odd_Numbers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# INPUT NUMBER OF ODD NUMBERS
2+
def print_error_messages():
3+
print("Invalid number, please enter a Non-negative number!")
4+
exit()
5+
6+
7+
try:
8+
n=int(input('Amount: '))
9+
except ValueError:
10+
print_error_messages()
211

3-
n=int(input('Amount: '))
412
start=1
513

14+
if n < 0:
15+
print_error_messages()
16+
617
for i in range(n):
718
print(start)
819
start+=2

0 commit comments

Comments
 (0)