-
Notifications
You must be signed in to change notification settings - Fork 1
/
section_17.py
98 lines (66 loc) · 2.2 KB
/
section_17.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
# with open("mydata.txt", mode="w", encoding="utf-8") as my_file:
# my_file.write("Some random text \nMore random text\nAnd more")
# with open("mydata.txt", encoding="utf-8") as my_file:
# print(my_file.read())
# print(my_file.closed)
# print(my_file.name)
# print(my_file.mode)
# os.rename("mydata.txt", "mydata2.txt")
# # os.remove("mydata2.txt")
# # os.mkdir("mydir")
# # os.chdir("mydir")
# # print("Current Directory : ", os.getcwd())
# with open("mydata2.txt", encoding="utf-8") as my_file:
# line_num = 1
# while True:
# line = my_file.readline()
# if not line:
# break
# print("Line : ", line_num, " : ", line,end = "")
# line_num += 1
# Python Problem for you to Solve
# For this problem I want you to cycle through each line of text and output the number of words and the average word length
# Here is sample output.
# Line 1
# Number of Words : 3
# Avg Word Length : 4.7
# Line 2
# Number of Words : 3
# Avg Word Length : 4.7
# import os
# with open("mydata2.txt", encoding="utf-8") as my_file:
# line_num = 1
# while True:
# line = my_file.readline()
# # line is empty so exit
# if not line:
# break
# print("Line", line_num)
# # Put the words in a list using the space as the boundary between words
# word_list = line.split()
# # Get the number of words with len()
# print("Number of Words :", len(word_list))
# # Incremented for each character
# char_count = 0
# for word in word_list:
# for char in word:
# char_count += 1
# # Divide to find the answer
# avg_num_chars = char_count/len(word_list)
# # Use format to limit to 2 decimals
# print("Avg Word Length : {:.2}".format(avg_num_chars))
# lineNum += 1
my_tuple = (1,2,3,5,8)
print("1st Value:", my_tuple[0])
print(my_tuple[0:3])
print("Length : ", len(my_tuple))
more_fibs = my_tuple + (13, 231, 34)
print("34 in Tuple :", 34 in more_fibs)
for i in more_fibs:
print(i)
a_list = [55, 89, 144]
a_tuple = tuple(a_list)
a_list = list(a_tuple)
print("Max : ", max(a_tuple))
print("Min : ", min(a_tuple))