File tree Expand file tree Collapse file tree 3 files changed +40
-8
lines changed Expand file tree Collapse file tree 3 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 8
8
9
9
givenPhrase = input ("\n Please input a phrase:(Press ENTER to use the sample phrase) " )
10
10
11
- if givenPhrase == "" or not givenPhrase . strip () :
11
+ if givenPhrase == "" :
12
12
print ("\n The sample phrase is: {0}" .format (samplePhrase ))
13
13
phrase = samplePhrase
14
14
else :
15
15
phrase = givenPhrase
16
16
17
- string = phrase .lower ()
17
+ phrase = phrase .lower ()
18
18
19
- if string == string [::- 1 ]:
20
- print ("\n Wow!, The phrase is a Palindrome!" )
21
- else :
22
- print ("\n Sorry, 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 ("\n Sorry, The given phrase is not a Palindrome." )
28
+ bol_ = False
29
+ break
30
+
31
+ if bol_ :
32
+ print ("\n Wow!, The phrase is a Palindrome!" )
Original file line number Diff line number Diff line change 1
1
# 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 ()
2
11
3
- n = int (input ('Amount: ' ))
4
12
start = 0
5
13
14
+ if n < 0 :
15
+ print_error_messages ()
16
+
6
17
for i in range (n ):
7
18
print (start )
8
19
start += 2
Original file line number Diff line number Diff line change 1
1
# 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 ()
2
11
3
- n = int (input ('Amount: ' ))
4
12
start = 1
5
13
14
+ if n < 0 :
15
+ print_error_messages ()
16
+
6
17
for i in range (n ):
7
18
print (start )
8
19
start += 2
You can’t perform that action at this time.
0 commit comments