forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request YearOfProgramming#186 from returnlove/master
challenge_0 in python
- Loading branch information
Showing
4 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
hello world. | ||
|
||
run: | ||
python helloworld.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("Hello World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Solution to reverse a string | ||
|
||
Run: | ||
|
||
python reverse_a_string.py | ||
type input string on the console and enter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# read input string from user | ||
input_string = raw_input("enter any string") | ||
|
||
# solution 1 | ||
# create a variable to store the reversed string | ||
reversed_string = "" | ||
|
||
# loop through the input in reverse order and append each letter | ||
for l in xrange(len(input_string)-1, -1, -1): | ||
reversed_string += str(input_string[l]) | ||
|
||
print('Solution 1: ',reversed_string) | ||
|
||
|
||
# solutin 2 | ||
print('Solution 2: ',''.join(reversed(input_string))) | ||
|
||
# solution 3 | ||
print('Solution 3: ',input_string[::-1]) |