-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ouch That Strings.py
69 lines (57 loc) · 2.03 KB
/
Ouch That Strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#welcome to "Ouch, That Strings!"
string = input("Please enter a phrase to play around with---->")
string += "."
print("Our String is:")
print(string, "\n\n")
input("\t\tPress ENTER to continue\n\n")
#center the string with +'s for padding
print("Here it is with the .center module:")
print(string.center(100, "+"), "\n")
input("\t\tPress ENTER to continue\n\n")
#count number of occurances
print("Here it is with the .count module to count the occurances of letter e:")
print(string.count("e"), "\n\n")
input("\t\tPress ENTER to continue\n\n")
#tells whether it ends with...
print("and Here using the .endswith module:\n")
print('---------String ends with "Water Balloon"---------')
print(string.endswith("Water Balloon"))
print("\n")
print('---------String ends with "stringFun.py"---------')
print(string.endswith("."), "\n\n")
input("\t\tPress ENTER to continue\n\n")
#find the position in a string where something is referenced
if "e" in string:
letter = string.find("e")
alpha = "e"
print('What is the first index in the string', alpha, 'is referenced?')
print(letter, "\n\n")
elif "a" in string:
letter = string.find("a")
alpha = "a"
print('What is the first index in the string', alpha, 'is referenced?')
print(letter, "\n\n")
else:
print("There aren't any E's or A's in your phrase.\n\n")
input("\t\tPress ENTER to continue\n\n")
#capitalize the string\
print("Here it is with the .capitalize module:")
print(string.capitalize(), "\n\n")
input("\t\tPress ENTER to continue\n\n")
#all lowercase
print("Here is the .lower module:")
print(string.lower(), "\n\n")
input("\t\tPress ENTER to continue\n\n")
#all caps
print("Here is the .upper module:")
print(string.upper(), "\n\n")
input("\t\tPress ENTER to continue\n\n")
#First letter of every word capitalized
print("Here is the .title module:")
print(string.title())
input("\t\tPress ENTER to continue\n\n")
#replace all occurances of string1 with string2
print("Here is the .replace module:")
print(string.replace("e", "3"))
input("\t\tPress ENTER to Exit\n\n")
exit(0)