Traceback (most recent call last):


File "<ipython-input-43-40df593e70bb>", line 1, in <module>

mysqrt(-2)


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py", line 113, in mysqrt

raise ValueError("input number is negative")


ValueError: input number is negative



In [44]: x = 2.0]

File "<ipython-input-44-de16336b8b5a>", line 1

x = 2.0]

^

SyntaxError: invalid syntax



In [45]: x = 2.0


In [46]: dir(x)

Out[46]:

['__abs__',

'__add__',

'__bool__',

'__class__',

'__delattr__',

'__dir__',

'__divmod__',

'__doc__',

'__eq__',

'__float__',

'__floordiv__',

'__format__',

'__ge__',

'__getattribute__',

'__getformat__',

'__getnewargs__',

'__gt__',

'__hash__',

'__init__',

'__int__',

'__le__',

'__lt__',

'__mod__',

'__mul__',

'__ne__',

'__neg__',

'__new__',

'__pos__',

'__pow__',

'__radd__',

'__rdivmod__',

'__reduce__',

'__reduce_ex__',

'__repr__',

'__rfloordiv__',

'__rmod__',

'__rmul__',

'__round__',

'__rpow__',

'__rsub__',

'__rtruediv__',

'__setattr__',

'__setformat__',

'__sizeof__',

'__str__',

'__sub__',

'__subclasshook__',

'__truediv__',

'__trunc__',

'as_integer_ratio',

'conjugate',

'fromhex',

'hex',

'imag',

'is_integer',

'real']


In [47]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [48]: mysqrt(-2)

Traceback (most recent call last):


File "<ipython-input-48-40df593e70bb>", line 1, in <module>

mysqrt(-2)


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py", line 114, in mysqrt

raise FileNotFoundError("input number is negative")


FileNotFoundError: input number is negative



In [49]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py", line 1

Revision 12

^

SyntaxError: invalid syntax



In [50]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')


In [51]: a

Out[51]: 'Revision\t12Practical classes and workshops\t20Project supervision\t28Supervised time in studio/workshop\t48Completion of assessment task\t96Lecture\t48Preparation for scheduled sessions\t48Total study time\t300'


In [52]: print(a)

Revision 12Practical classes and workshops 20Project supervision 28Supervised time in studio/workshop 48Completion of assessment task 96Lecture 48Preparation for scheduled sessions 48Total study time 300


In [53]: "Hello" + "World"

Out[53]: 'HelloWorld'


In [54]: "Hello" + " " + "World"

Out[54]: 'Hello World'


In [55]: "Hello" + "\t" + "World"

Out[55]: 'Hello\tWorld'


In [56]: print("Hello" + " " + "World")

Hello World


In [57]: print("Hello" + "" + "World")

HelloWorld


In [58]: print("Hello" + "\t" + "World")

Hello World


In [59]: print("Hello" + "\n" + "World")

Hello

World


In [60]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')


In [61]: a

Out[61]: 'Revision\t12\nPractical classes and workshops\t20\nProject supervision\t28\nSupervised time in studio/workshop\t48\nCompletion of assessment task\t96\nLecture\t48\nPreparation for scheduled sessions\t48\nTotal study time\t300'


In [62]: print(a)

Revision 12

Practical classes and workshops 20

Project supervision 28

Supervised time in studio/workshop 48

Completion of assessment task 96

Lecture 48

Preparation for scheduled sessions 48

Total study time 300


In [63]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

['Revision\t12', 'Practical classes and workshops\t20', 'Project supervision\t28', 'Supervised time in studio/workshop\t48', 'Completion of assessment task\t96', 'Lecture\t48', 'Preparation for scheduled sessions\t48', 'Total study time\t300']


In [64]: a_after_split

Out[64]:

['Revision\t12',

'Practical classes and workshops\t20',

'Project supervision\t28',

'Supervised time in studio/workshop\t48',

'Completion of assessment task\t96',

'Lecture\t48',

'Preparation for scheduled sessions\t48',

'Total study time\t300']


In [65]: a_after_split[0]

Out[65]: 'Revision\t12'


In [66]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

['Revision\t12\nPractical classes and workshops\t20\nProject supervision\t28\nSupervised time in studio/workshop\t48\nCompletion of assessment task\t96\nLecture\t48\nPreparation for scheduled ', '\t48\nTotal study time\t300']


In [67]: a_after_split

Out[67]:

['Revision\t12\nPractical classes and workshops\t20\nProject supervision\t28\nSupervised time in studio/workshop\t48\nCompletion of assessment task\t96\nLecture\t48\nPreparation for scheduled ',

'\t48\nTotal study time\t300']


In [68]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

['Revision\t12', 'Practical classes and workshops\t20', 'Project supervision\t28', 'Supervised time in studio/workshop\t48', 'Completion of assessment task\t96', 'Lecture\t48', 'Preparation for scheduled sessions\t48', 'Total study time\t300']


In [69]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

['Revision\t12', 'Practical classes and workshops\t20', 'Project supervision\t28', 'Supervised time in studio/workshop\t48', 'Completion of assessment task\t96', 'Lecture\t48', 'Preparation for scheduled sessions\t48', 'Total study time\t300']


In [70]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')


In [71]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

Revision 12


In [72]: type(a1)

Out[72]: str


In [73]: a1

Out[73]: 'Revision\t12'


In [74]: a

Out[74]: 'Revision\t12\nPractical classes and workshops\t20\nProject supervision\t28\nSupervised time in studio/workshop\t48\nCompletion of assessment task\t96\nLecture\t48\nPreparation for scheduled sessions\t48\nTotal study time\t300'


In [75]: a_after_split

Out[75]:

['Revision\t12',

'Practical classes and workshops\t20',

'Project supervision\t28',

'Supervised time in studio/workshop\t48',

'Completion of assessment task\t96',

'Lecture\t48',

'Preparation for scheduled sessions\t48',

'Total study time\t300']


In [76]: a1

Out[76]: 'Revision\t12'


In [77]: a1.split("\t")

Out[77]: ['Revision', '12']


In [78]: a1.split("\t")[1]

Out[78]: '12'


In [79]: float(a1.split("\t")[1])

Out[79]: 12.0


In [80]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12


In [81]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0


In [82]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

20.0


In [83]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

Traceback (most recent call last):


File "<ipython-input-83-7af855ff47fe>", line 1, in <module>

runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')


File "C:\Apps\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile

execfile(filename, namespace)


File "C:\Apps\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py", line 11, in <module>

a1 = float(a_after_split[1].split("\t")[2])


IndexError: list index out of range



In [84]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

300.0

12.0

20.0

28.0

48.0

96.0

48.0

48.0

300.0


In [85]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

12.0

20.0

28.0

48.0

96.0

48.0

48.0

300.0


In [86]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0


In [87]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

300.0


In [88]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

The sum of working hours is: 300.0


In [89]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

The sum of working hours is: 300.0


In [90]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/lecture5b.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5')

12.0

20.0

28.0

48.0

96.0

48.0

48.0

300.0

The sum of working hours is: 600.0


In [91]: a_after_split

Out[91]:

['Revision\t12',

'Practical classes and workshops\t20',

'Project supervision\t28',

'Supervised time in studio/workshop\t48',

'Completion of assessment task\t96',

'Lecture\t48',

'Preparation for scheduled sessions\t48',

'Total study time\t300']


In [92]: a_after_split[1]

Out[92]: 'Practical classes and workshops\t20'


In [93]: v = 10


In [94]: v += 1


In [95]: v

Out[95]: 11


In [96]: v = v + 1


In [97]: vv

Traceback (most recent call last):


File "<ipython-input-97-2402e89dcb61>", line 1, in <module>

vv


NameError: name 'vv' is not defined



In [98]: v

Out[98]: 12


In [99]: v -= 1


In [100]: v

Out[100]: 11


In [101]: v *= 2


In [102]: c

Traceback (most recent call last):


File "<ipython-input-102-2cd6ee2c70b0>", line 1, in <module>

c


NameError: name 'c' is not defined



In [103]: v

Out[103]: 22


In [104]: v /= 2


In [105]: v

Out[105]: 11.0


In [106]: v = v / 2


In [107]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [108]: print_line_sum_of_file("data.dat")

Out[108]: (380.0, 50.0, 17.0)


In [109]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [110]: print_line_sum_of_file("data.dat")

['1 2 4 67 -34 340\n', '0 45 3 2\n', '17\n']

Out[110]: (380.0, 50.0, 17.0)


In [111]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [112]: print_line_sum_of_file("data.dat")

['1 2 4 67 -34 340\n', '0 45 3 2\n', '17\n']

1 2 4 67 -34 340


0 45 3 2


17


Out[112]: (380.0, 50.0, 17.0)


In [113]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [114]: print_line_sum_of_file("data.dat")

['1 2 4 67 -34 340\n', '0 45 3 2\n', '17\n']

1 2 4 67 -34 340


['1', '2', '4', '67', '-34', '340\n']

0 45 3 2


['0', '45', '3', '2\n']

17


['17\n']

Out[114]: (380.0, 50.0, 17.0)


In [115]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises')


In [116]: print_line_sum_of_file("data.dat")

['1 2 4 67 -34 340\n', '0 45 3 2\n', '17\n']

1 2 4 67 -34 340


['1', '2', '4', '67', '-34', '340\n']

380.0

0 45 3 2


['0', '45', '3', '2\n']

50.0

17


['17\n']

17.0

Out[116]: (380.0, 50.0, 17.0)


In [117]: print_line_sum_of_file("data.dat")

['1 2 4 67 -34 340\n', '0 45 3 2\n', '17\n']

1 2 4 67 -34 340


['1', '2', '4', '67', '-34', '340\n']

380.0

0 45 3 2


['0', '45', '3', '2\n']

50.0

17


['17\n']

17.0

Out[117]: (380.0, 50.0, 17.0)


In [118]: print_line_sum_of_file("data.txt")

['1 2 4\n', '1 cat 4\n', 'coffee\n']

1 2 4


['1', '2', '4\n']

7.0

1 cat 4


['1', 'cat', '4\n']

Traceback (most recent call last):


File "<ipython-input-118-50f485ac6fd8>", line 1, in <module>

print_line_sum_of_file("data.txt")


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture5/exercises/lecture5_exceptions.py", line 135, in print_line_sum_of_file

jfl = float(j)


ValueError: could not convert string to float: 'cat'



In [119]: float("cat")

Traceback (most recent call last):


File "<ipython-input-119-2c034d0e6121>", line 1, in <module>

float("cat")


ValueError: could not convert string to float: 'cat'



In [120]: print_line_sum_of_file1("data.txt")

Out[120]: [7.0, 5.0, 0.0]


In [121]: ord("cat")

Traceback (most recent call last):


File "<ipython-input-121-1b51ab03bb38>", line 1, in <module>

ord("cat")


TypeError: ord() expected a character, but string of length 3 found



In [122]: