-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathhomework01_B05505018.py
55 lines (41 loc) · 1.08 KB
/
homework01_B05505018.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
file = open("./sample.txt","r")
text = file.read()
file.close()
text = text.replace("?","")
text = text.replace(",","")
text = text.replace("-","")
text = text.replace("\"","")
text = text.replace(".","")
text = text.replace("2000th","2,000th")
text = text.replace("\n"," ")
samplewordlist=[]
wordlist = text.split(" ")
for word in wordlist:
if len(word)>5:
samplewordlist.append(word)
print ("samplewordlist:")
print (samplewordlist)
samplewordlist1=[]
newwordlist1=[]
wordlist1 = text.lower()
newwordlist = wordlist1.split(" ")
for word in newwordlist:
if len(word)>5:
newwordlist1.append(word)
userword = input("Please enter a word which contains more than five characters:").lower()
i = 0
x = 0
while i < len(samplewordlist) :
if len(userword)<=5:
x= 2
break
elif userword == newwordlist1[i]:
x = 1
break
i = i+1
if x==2:
print("U should enter a word with more than five characters.")
if x==1:
print ("The word is also in the article!")
if x==0:
print ("The word is not in the article!")