-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_reading_methods
56 lines (41 loc) · 1.45 KB
/
file_reading_methods
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
#Task 1:
#Using the file school_prompt2.txt, find the number of characters in the file and assign that value to the variable num_char.
fileref = open("school_prompt2.txt","r")
num_char = 0
for char in fileref:
num_char += len(char)
print(num_char)
fileref.close()
#Task 2:
#This summer I will be travelling.
#I will go to...
#Italy: Rome
#Greece: Athens
#England: London, Manchester
#France: Paris, Nice, Lyon
#Spain: Madrid, Barcelona, Granada
#Austria: Vienna
#I will probably not even want to come back!
#However, I wonder how I will get by with all the different languages.
#I only know English!
#Find the number of lines in the file, travel_plans2.txt, and assign it to the variable num_lines.
fileref = open("travel_plans2.txt","r")
for num_lines,line in enumerate(fileref):
pass
num_lines = num_lines + 1
print(num_lines)
fileref.close()
#Task 3:
#Sad upset blue down melancholy somber bitter troubled
#Angry mad enraged irate irritable wrathful outraged infuriated
#Happy cheerful content elated joyous delighted lively glad
#Confused disoriented puzzled perplexed dazed befuddled
#Excited eager thrilled delighted
#Scared afraid fearful panicked terrified petrified startled
#Nervous anxious jittery jumpy tense uneasy apprehensive
#Create a string called first_forty that is comprised of the first 40 characters of emotion_words2.txt.
fileref = open("emotion_words2.txt","r")
chars = fileref.read()
first_forty = chars[:40]
print(first_forty)
fileref.close()