From f482a64d4b9364c0e756bc923c95268f584b206d Mon Sep 17 00:00:00 2001 From: Aakash Singh <17aakashsingh1999@gmail.com> Date: Tue, 29 May 2018 16:39:58 +0530 Subject: [PATCH] session5 --- .../Session-5/aakash_singh/q3.py | 11 +++++++++++ .../Session-5/aakash_singh/q4.py | 12 ++++++++++++ .../Session-5/aakash_singh/theory.txt | 7 +++++++ 3 files changed, 30 insertions(+) create mode 100644 Introduction-to-Data-Science/Session-5/aakash_singh/q3.py create mode 100644 Introduction-to-Data-Science/Session-5/aakash_singh/q4.py create mode 100644 Introduction-to-Data-Science/Session-5/aakash_singh/theory.txt diff --git a/Introduction-to-Data-Science/Session-5/aakash_singh/q3.py b/Introduction-to-Data-Science/Session-5/aakash_singh/q3.py new file mode 100644 index 0000000..400198c --- /dev/null +++ b/Introduction-to-Data-Science/Session-5/aakash_singh/q3.py @@ -0,0 +1,11 @@ +try: + n=int(input('enter a number: ')) +except ValueError: + print('please try again and input a number') + exit() + +try: + print(100/n) +except ZeroDivisionError: + print('cant divide by zero') + exit() \ No newline at end of file diff --git a/Introduction-to-Data-Science/Session-5/aakash_singh/q4.py b/Introduction-to-Data-Science/Session-5/aakash_singh/q4.py new file mode 100644 index 0000000..2b0bac2 --- /dev/null +++ b/Introduction-to-Data-Science/Session-5/aakash_singh/q4.py @@ -0,0 +1,12 @@ +import sys + +try: + file = open(sys.argv[1],'r') +except: + print('file doesnt exist') + exit() + +lines=file.read().split('\n') +file.close() +for line in lines[::-1]: + print(line.strip()) \ No newline at end of file diff --git a/Introduction-to-Data-Science/Session-5/aakash_singh/theory.txt b/Introduction-to-Data-Science/Session-5/aakash_singh/theory.txt new file mode 100644 index 0000000..bf81f1e --- /dev/null +++ b/Introduction-to-Data-Science/Session-5/aakash_singh/theory.txt @@ -0,0 +1,7 @@ +q1: + ab+ mode expands to append binary read and write. + The file at default opens with cursor at EOF in binary mode and can be read or written to. + +q2. + buffering means that python is not directly interfacing with the OS's representation of a file or its file system. + Instead only a chunk of data is read from the raw OS filestream into a buffer. \ No newline at end of file