Tuesday, December 2, 2014

1.3.5 Conclusion Questions
1.       Q: How many characters are in this sentence? Does it matter whether Python is storing the string as one byte per character or four bytes per character?

          A: There are 41 characters in "How many characters are in this sentence?". It doesn't matter for our purposes whether Python stores each character as one byte or four bytes. However, It may make the program use more memory while running.

2.       Q: This question asks you about something you have not learned. In fact, the question is asking about details that go beyond what you will learn in this course. However, wondering what is going on at a lower level of abstraction – and talking about it – can be a useful strategy when learning about computing.

Describe what you think occurs in memory when the following code is executed.

In []: a = 'one string'
In []: b = 'another'
In []: c = a[:3] + ' and ' + b
In []: print(c[6:10])


        A: When this code is executed I believe that 'a' is given the value 'one string'. Then 'b' is given 'another'. The computer then racalls 'a' and takes the first 3 indexes (one). It then combines that with ' and '. It then recalls 'b' form memory and adds it to the end to get 'one and another'. that is set to 'c'. The computer the recalls 'c' and take the indexes between 6 and 10 (d an) and prints them.

1.3.5 Tweet Verifier File
1.       def how_eligible(tweet):
2.          'Runs through various if statements and adds 1 to variable num if it is true.'
3.          num = 0
4.          if '!' in tweet:
5.              'Starts checking for ! in the text.'
6.              num += 1
7.              if '?' in tweet:
8.                 'Starts checking for ? in the text.'
9.                  num += 1
10.              if ',' in tweet:
11.                   'Starts checking for , in the text.'
12.                  num += 1
13.                  if '"' in tweet:
14.                      'Starts checking for " in the text.'
15.                       num += 1
16.                      if len(tweet) <= 140:
17.                           'Starts checking for the text to be less than 140 characters.'
18.                          num += 1
19.                          print(num)
20.                     else:
21.                          '>140'
22.                         print(num)
23.                 else:
24.                     'No "'
25.                      if len(tweet) <= 140:
26.                         num += 1
27.                          print(num)
28.                         'Last check so prints'
29.                     else:
30.                         '>140'
31.                          print(num)
32.                         'Last check so prints'
33.             else:
34.                 'No ,'
35.                  if '"' in tweet:
36.                     num += 1
37.                      if len(tweet) <= 140:
38.                         num += 1
39.                         print(num)
40.                         'Last check so prints'
41.                      else:
42.                         '>140'
43.                         print(num)
44.                         'Last check so prints'
45.                  else:
46.                     'No "'
47.                      if len(tweet) <= 140:
48.                         num += 1
49.                         print(num)
50.                         'Last check so prints'
51.                       else:
52.                          '>140'
53.                          print(num)
54.                          'Last check so prints'   
55.          else:
56.              'No ?'
57.              if ',' in tweet:
58.                 num += 1
59.                  if '"' in tweet:
60.                     num += 1
61.                      if len(tweet) <= 140:
62.                         num += 1
63.                         print(num)
64.                         'Last check so prints'
65.                      else:
66.                         '>140'
67.                          print(num)
68.                         'Last check so prints'
69.                 else:
70.                     'No "'
71.                       if len(tweet) <= 140:
72.                          num += 1
73.                          print(num)
74.                          'Last check so prints'
75.                      else:
76.                          '>140'
77.                          print(num)
78.                         'Last check so prints'
79.              else:
80.                'No ,'
81.                  if '"' in tweet:
82.                     num += 1
83.                     if len(tweet) <= 140:
84.                         num += 1
85.                         print(num)
86.                         'Last check so prints'
87.                     else:
88.                        '>140'
89.                         print(num)
90.                         'Last check so prints'
91.                  else:
92.                     'No "'
93.                     if len(tweet) <= 140:
94.                         num += 1
95.                          print(num)
96.                         'Last check so prints'
97.                      else:
98.                         '>140'
99.                         print(num)
100.                                             'Last check so prints'
101.                          else:
102.                             'No !'
103.                             if '?' in tweet:
104.                                 num += 1
105.                                  if ',' in tweet:
106.                                     num += 1
107.                                      if '"' in tweet:
108.                                         num += 1
109.                                         if len(tweet) <= 140:
110.                                              num += 1
111.                                                print(num)
112.                                               'Last check so prints'
113.                                           else:
114.                                               '>140'
115.                                               print(num)
116.                                               'Last check so prints'
117.                                       else:
118.                                          'No "'
119.                                           if len(tweet) <= 140:
120.                                             num += 1
121.                                               print(num)
122.                                              'Last check so prints'
123.                                          else:
124.                                              '>140'
125.                                              print(num)
126.                                              'Last check so prints'
127.                                  else:
128.                                     'No ,'
129.                                      if '"' in tweet:
130.                                         num += 1
131.                                           if len(tweet) <= 140:
132.                                              num += 1
133.                                              print(num)
134.                                              'Last check so prints'
135.                                          else:
136.                                              '>140'
137.                                              print(num)
138.                                             'Last check so prints'
139.                                      else:
140.                                         'No "'
141.                                           if len(tweet) <= 140:
142.                                              num += 1
143.                                              print(num)
144.                                              'Last check so prints'
145.                                          else:
146.                                              '>140'
147.                                              print(num)
148.                                             'Last check so prints'
149.                              else:
150.                                  'No ?'
151.                                   if ',' in tweet:
152.                                      num += 1
153.                                      if '"' in tweet:
154.                                          num += 1
155.                                           if len(tweet) <= 140:
156.                                              num += 1
157.                                               print(num)
158.                                              'Last check so prints'
159.                                          else:
160.                                             '>140'
161.                                               print(num)
162.                                              'Last check so prints'
163.                                      else:
164.                                          'No "'
165.                                          if len(tweet) <= 140:
166.                                              num += 1
167.                                              print(num)
168.                                             'Last check so prints'
169.                                          else:
170.                                              '>140'
171.                                               print(num)
172.                                              'Last check so prints'
173.                                  else:
174.                                      'No ,'
175.                                       if '"' in tweet:
176.                                          num += 1
177.                                           if len(tweet) <= 140:
178.                                              num += 1
179.                                              print(num)
180.                                             'Last check so prints'
181.                                          else:
182.                                             '>140'
183.                                             print(num)
184.                                             'Last check so prints'
185.                                      else:
186.                                         'No "'
187.                                          if len(tweet) <= 140:
188.                                             num += 1
189.                                             print(num)
190.                                             'Last check so prints'
191.                                           else:
192.                                              '>140'
193.                                              print(num)

194.                                   'Last check so prints'

No comments:

Post a Comment