-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathhomework01_b05505026.py
54 lines (42 loc) · 1.07 KB
/
homework01_b05505026.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
#=======================================homework1-1
#impot sample.txt
F=open("sample.txt","r")
FF=F.read()
F.close()
#delete invalid characters
FF=FF.replace("?"," ")
FF=FF.replace(","," ")
FF=FF.replace("2"," ")
FF=FF.replace("0"," ")
FF=FF.replace("1"," ")
FF=FF.replace("."," ")
FF=FF.replace("-"," ")
FF=FF.replace("\n"," ")
FF=FF.replace("\""," ")
FFlist=FF.split(" ")
sampleWordList=[]
for i in FFlist:
if len(i) >5 :
sampleWordList+=[i]
#Output the list
print("sampleWordList :")
print(sampleWordList)
print("\n")
#=======================================homework1-2
#Use x as the condition
x=1
#Use loop to select the correct word
while x==1:
word=input("Please enter a word containing 5 letter at least.")
word=str(word)
if len(word) <5:
print("You should type more letter.")
x=1
else:
if (word in sampleWordList)==1:
print("The word is in the sampleWordList.")
print("Finish")
x=2
else:
print("The word isn't in the sampleWordList.")
x=1