Skip to content

Commit 13674a9

Browse files
committed
Second week of my python for beginners.
1 parent 77ef733 commit 13674a9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

naya.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#finding length of string built in function
2+
#len() function
3+
x = "kkkkkk"
4+
print(len(x))

reversestr.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
strng = input("Enter a string: ")
2+
length = len(strng)
3+
4+
# method 1
5+
for i in range(length):
6+
print(strng[length - i - 1], end = "")
7+
8+
# method 2
9+
for i in range(length - 1, -1, -1):
10+
print(strng[i], end = "")
11+
12+
# method 3
13+
print(strng[::-1])
14+
15+
# method 4
16+
print("".join(reversed(strng)))
17+
18+
# method 5
19+
print("".join(strng[length - i - 1] for i in range(length)))
20+
21+
# method 6
22+
print("".join(strng[i] for i in range(length - 1, -1, -1)))
23+
24+
# method 7
25+
print("".join(strng[i] for i in reversed(range(length))))
26+
27+
# method 8
28+
print("".join(strng[i] for i in range(length))[::-1])
29+
30+
31+
32+

0 commit comments

Comments
 (0)