[Solved] COMP1007 Lab 4- Text Processing
5.0
1 customer review
Digital download
Digital download
$25.00
Upload assignment
| name = Alicetype(name) print(name[3]) | #c |
| print(len(name)) | #5 |
| print(name + Lee) | #Alice Lee |
| s = HkbUCs print(s.upper()) #HKBUCS print(s.lower()) #hkbucs help(s.lower) #dont put () at the end of s.lower! |
| s1 = HkbUCs s2 = 1000 s3 = 1000. s3 = print(s1.isalpha()) | #True |
| print(s2.isdigit()) | #True |
| print(s3.isdigit()) | #False |
| print(s4.isspace()) | #True |
| s = CS is fun! print(s.startswith(CS)) | #True |
| print(s.endswith(un!)) | #True |
| print(s.endswith(UN!)) | #Case sensitive, False |
| s = CS is fun! print(s.find(fun)) | #6 |
| s = CS is fun! words = s.split( ) print(words) | #[CS, is, fun!] |
| s = words = [CS, is, fun, !] s = s.join(words)print(s) | #CSisfun! |
| m = .join(words)print(m) | #CS is fun! |
| myString = He said, Hi! Stop! Stop!' import string # to access the string.punctuation for c in string.punctuation: myString = myString.replace(c, )words = myString.split( ) # split the sentence into words print(words) |
| text = {0}! You have a meeting with {1} at {2}:{3} pm..format(Good Morning, Alice, 3, 30) print(text)# Good Morning! You have a meeting with Alice at 3:30 pm. |
| file1 = open(demo.txt, r) # file1 is a file object content = file1.read() # read all data from file1 as a stringfile1.close() # close file1. Now we cannot access demo.txt through file1 print(content) |
| file1 = open(demo.txt, r)s = file1.readline() # read a line from demo.txt, including the last print(s) print()s = file1.readline() # read another line from demo.txt print(s) file1.close() |
| file1 = open(demo.txt, r) s = file1.readline()while s != : # when reach the end of the file, s should become empty print(s)s = file1.readline() file1.close() |
| file1 = open(demo.txt, r) lines = file1.readlines() file1.close()print(len(lines)) # check the number of lines in demo.txt for s in lines: # iterate the list of lines print(s) |