Tuesday, September 28, 2021

Skin Allergy (Jun-2017)



Tags: Medical Prescription,Journal

Patience (Joke and Lesson)



I was 25. Years, not Kilograms. Looking for bride.
Now my family puts up a lot of conditions of the selection of the girl. As follows:

At 25: Jain girl with Jain diet

I turned 26 with no match found. Now my family reduces constraints.

26: Find a Jain girl.

I turned 27 with no match found. My family reduces the constraints further.

27: Find a Jain or Gupta girl.

I turned 28 with no match found. My family reduces the constraints further.

28: Just a vegetarian girl would be fine.

I turned 29 with no luck yet in finding a girl. My family reduces constraints further.

29: My family says unemployed girl would also do fine.

My friend Sandeep tells me that wait for 5 more years and they would agree to a girl who does smack and coke.

Patience is the key ingredient to successful execution of any plan.
Journal,Joke,

Sunday, September 26, 2021

Packaged Food (2021-Sep-26)



Index of Journals

Thursday, September 23, 2021

Cold (Sep-2017, Dr Ajay Dewan)

Steps toward: virtualenv, jupyter notebook, jupyterlab, ipykernel, SpaCy model (en_core_web)



Steps toward: virtualenv, jupyter notebook, jupyterlab, ipykernel, SpaCy model (en_core_web)

$ pip install virtualenv
$ virtualenv ve1 --python=python3.8

INSTALL JUPYTER NOTEBOOK AND JUPYTERLAB FROM TERMINAL ON UBUNTU:

$ sudo apt install jupyter-core
$ pip install jupyter
$ pip install jupyterlab

(ve1) $ python3 -m notebook

[I 11:56:51.871 NotebookApp] Writing notebook server cookie secret to /home/ashi/.local/share/jupyter/runtime/notebook_cookie_secret
[I 11:56:52.175 NotebookApp] Serving notebooks from local directory: /home/ashi/Desktop/ws
[I 11:56:52.175 NotebookApp] Jupyter Notebook 6.4.4 is running at:
[I 11:56:52.175 NotebookApp] http://localhost:8888/?token=1b335a35516298724494a1ff32e309334d3a819a633719fc
[I 11:56:52.175 NotebookApp]  or http://127.0.0.1:8888/?token=1b335a35516298724494a1ff32e309334d3a819a633719fc
[I 11:56:52.175 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 11:56:52.221 NotebookApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/ashi/.local/share/jupyter/runtime/nbserver-13598-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=1b335a35516298724494a1ff32e309334d3a819a633719fc
        or http://127.0.0.1:8888/?token=1b335a35516298724494a1ff32e309334d3a819a633719fc
/usr/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
    return _iterencode(o, 0)
[W 11:56:59.140 NotebookApp] 404 GET /lab/tree/Desktop (127.0.0.1) 15.820000ms referer=None

###   ###   ###   ###   ###   

(ve1) $ python3 -m jupyterlab

[I 2021-09-22 11:58:03.326 ServerApp] jupyterlab | extension was successfully linked.
[I 2021-09-22 11:58:03.357 LabApp] JupyterLab extension loaded from /home/ashi/.local/lib/python3.9/site-packages/jupyterlab
[I 2021-09-22 11:58:03.357 LabApp] JupyterLab application directory is /home/ashi/.local/share/jupyter/lab
[I 2021-09-22 11:58:03.360 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-09-22 11:58:03.361 ServerApp] The port 8888 is already in use, trying another port.
[I 2021-09-22 11:58:03.361 ServerApp] Serving notebooks from local directory: /home/ashi/Desktop/ws/ve1/bin
[I 2021-09-22 11:58:03.361 ServerApp] Jupyter Server 1.11.0 is running at:
[I 2021-09-22 11:58:03.362 ServerApp] http://localhost:8889/lab?token=9bcab4ac0599e2c3c086f1ace8376d6d8221fd074bdaf066
[I 2021-09-22 11:58:03.362 ServerApp]  or http://127.0.0.1:8889/lab?token=9bcab4ac0599e2c3c086f1ace8376d6d8221fd074bdaf066
[I 2021-09-22 11:58:03.362 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 2021-09-22 11:58:03.371 ServerApp] No web browser found: could not locate runnable browser.
[C 2021-09-22 11:58:03.371 ServerApp] 
    
    To access the server, open this file in a browser:
        file:///home/ashi/.local/share/jupyter/runtime/jpserver-14003-open.html
    Or copy and paste one of these URLs:
        http://localhost:8889/lab?token=9bcab4ac0599e2c3c086f1ace8376d6d8221fd074bdaf066
        or http://127.0.0.1:8889/lab?token=9bcab4ac0599e2c3c086f1ace8376d6d8221fd074bdaf066
[W 2021-09-22 11:58:44.209 LabApp] Could not determine jupyterlab build status without nodejs
[W 2021-09-22 11:58:47.988 ServerApp] 404 GET /api/contents/Desktop?1632292127985 (127.0.0.1): No such file or directory: Desktop
[W 2021-09-22 11:58:47.988 ServerApp] No such file or directory: Desktop
[W 2021-09-22 11:58:47.988 ServerApp] 404 GET /api/contents/Desktop?1632292127985 (127.0.0.1) 1.34ms referer=http://127.0.0.1:8889/lab

###   ###   ###   ###   ###   

$ pip install ipykernel

(ve1) ashi@ashi-VirtualBox:/home/ashi/Desktop/ws$ python3 -m ipykernel install --name ve1
[Errno 13] Permission denied: '/usr/local/share/jupyter'
(ve1) ashi@ashi-VirtualBox:/home/ashi/Desktop/ws$ python3 -m ipykernel install --user --name ve1
Installed kernelspec ve1 in /home/ashi/.local/share/jupyter/kernels/ve1


###   ###   ###   ###   ###   

(ve1) ashi@ashi-VirtualBox:/home/ashi/Desktop/ws$ python3 -m spacy download en_core_web_sm
Collecting en-core-web-sm==3.1.0
    WARNING: Retrying (Retry(total=4.... connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)'))': /explosion/spacy-models/releases/download/en_core_web_sm-3.1.0/en_core_web_sm-3.1.0-py3-none-any.whl
ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /explosion/spacy-models/releases/download/en_core_web_sm-3.1.0/en_core_web_sm-3.1.0-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

We download the wheel file from the GitHub link and install as follows
$ pip install en_core_web_sm-3.1.0-py3-none-any.whl

###   ###   ###   ###   ###   
Tags: Python,Technology,Anaconda,

Tuesday, September 21, 2021

Anaconda Setup on Ubuntu for the First Time



First time Anaconda setup is done using the following commands:

1. 
~/Downloads$ ls -l
total 712608
-rwxrwxrwx 1 ashi ashi 570853747 Sep 21 12:43 Anaconda3-2021.05-Linux-x86_64.sh

2. 
$ chmod 777 Anaconda3-2021.05-Linux-x86_64.sh

3. 
~/Downloads$ ./Anaconda3-2021.05-Linux-x86_64.sh 

4. 
$ cd ~/anaconda3/bin

5. 
~/anaconda3/bin$ ./conda init bash 

no change     /home/ashi/anaconda3/condabin/conda
no change     /home/ashi/anaconda3/bin/conda
no change     /home/ashi/anaconda3/bin/conda-env
no change     /home/ashi/anaconda3/bin/activate
no change     /home/ashi/anaconda3/bin/deactivate
no change     /home/ashi/anaconda3/etc/profile.d/conda.sh
no change     /home/ashi/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/ashi/anaconda3/shell/condabin/Conda.psm1
no change     /home/ashi/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/ashi/anaconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change     /home/ashi/anaconda3/etc/profile.d/conda.csh
modified      /home/ashi/.bashrc

==> For changes to take effect, close and re-open your current shell. <== 

CHANGES AUTOMATICALLY PUSHED IN THE FILE: /home/ashi/.bashrc
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/ashi/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/ashi/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/ashi/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/ashi/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<


~/anaconda3/bin$ ./conda activate base

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
    - bash
    - fish
    - tcsh
    - xonsh
    - zsh
    - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'. 

6.
~/anaconda3/bin$ bash

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

(base) ~/anaconda3/bin$
Tags: Technology,Anaconda,Python,

Monday, September 20, 2021

2011-Feb-16 (Night fall)



Index of Journals
February 16, 2011

I was not supposed to be awakening early this morning had I not been having night-fall in the bed. Well, it was okay since I had things to study. I was not about to do math-like subject with brain still partially asleep. I read the Software Engineering text book, a theoretical subject. Now I was feeling lucky for not having attending to classes of this bullshit. 

I took to reading “Accidental Billionaires” by Ben Mezrich on the founding of the ‘Facebook’. The story still inspires me, again, and over again. 

In the morning the security guard, Amar-singh entangled with some man who had problem with the watchman. Watchman claimed that the man abused him before starting to talk and the discussion was given a new useless shape far away from the reason why it was born. An abuse could do this much, surprising. 

Gurarchi still texts me, probably because she got Anurag to explain her about my situation. Anurag had gone far from me last year but because we have a mutual contact, and more because it is a girl, Anurag is again a close friend. 

I didn’t remove a wrong tag from my Facebook profile for school-friends. I anyway don’t use it so it didn’t seem important to me. Now, there’s only one photo of me with other boys of XII-D and then there’s a photo of senior ‘Ashish Jain’, whom I better know as Anu’s ex-boyfriend.

God Bless ‘Me’
Ashish 

2011-Feb-15 (Mass Bunk culture at ADGITM)



Index of Journals
February 15, 2011

Dhanraj, Dinesh, and I were climbing the stairs when Dhanraj said he hadn’t seen Neeru madam’s face since many days. And Neeru ma’am was standing right on the next floor to see us coming, she heard him clearly. I was about to comment but then I cautiously stopped. It was 8am class. I was like about to fall while sitting on the first bench and Neeru ma’am had to comment that if I was to fall like this in first period then god only knows what would happen in the later ones. 

Aditya is ignoring me. Well it wasn’t my fault when he came late for the ADA class and sir said, “Nice to meet you, Tata-bye-bye,” from the closed door. I was on the first bench but I couldn’t have helped in any way. 

In Computer Graphics lab, that jerk teacher made my day awful. Anshul-whatever is his name. Yes, he had once come to take OOPS substitution last semester and then started teaching us Yoga and breathing exercises. I have got to dislike him. He speaks as if he’s just learning to speak. Tanvi Gautam is a slut, I will say this on every day I will have an encounter with her. One good thing about Anshul sir is that though I’m never writing in his period but he never punished me for that. 

Faizan never brings his own lunch and pecks on the lunch boxes of those who get it. It is sick to share food with people like him, Kirti Mohan was another, idiots.

When students called out for mass bunk in the last period off Software Engineering, many were not in the mood to do that. Some were sitting in the class, and the mass-bunkers had already come out with bags packed. When the teacher came to the class, they came in with her and made the teacher leave with attendance. Swarnlata ma’am is such an idiot, young, beautiful, and an idiot. I was almost on my nerves when I saw the back benchers made the teacher leave. I mean, what are the rest of the all who were sitting to attend the class, donkeys? And, it made me so irritated because though being the class coordinator I was able to do nothing, I had no say. I couldn’t have said anything. Only this thing was pissing me off for another hour after that. But then I settled with the thought that self-studying is way better than attending to an idiot on lecturer’s post. And that applies to almost every teacher in this college. I hate NIEC.

God Bless ‘Me’
Ashish 

2011-Feb-14 (Clean-up of Facebook Profile)



Index of Journals
February 14, 2011

Happy Valentines Day
I woke up on time around 0630. I went to college but missed the 8am class, Swarnlata madam‘s class again.
I was marked absent for not bringing the file by this pathetic woman, Neeru ma’am, in the DCS (Digital Circuits and Systems) lab. The period after break, CS communication systems class, was mass-bunked and class attended DCS, Neeru madam’s period. 
I sat in library till 1800 and I had this nice bus ride to get back home.

I deleted my song ‘Flashback’ from my school-profile on Facebook before accepting Jagdish (JD sir, my high school class teacher) sir’s friend request. I had written that song to just speak out my unsaid thoughts and feelings about my school life-and-Sonal to my school friends and Sonal. That song posted in May 2010 after declaration of JEE result just got deleted. I very critically acclaimed by many who were tagged in that note and who read that note. It was my first public release. I removed “married to my ego” thing from “about me” column, but didn’t change my “married” relationship status. And my birthday date is 18th Dec again. 

Babaji handed me R500 note in the morning for studying. Now, my money-packet is pregnant again, it breached R4700 mark after 1 year and 3 months. 

God Bless ‘Me’
Ashish 

Sunday, September 19, 2021

Packaged Food (2021-Sep-19)



Index of Journals

Friday, September 17, 2021

2011-Feb-13 (Granny, grandpa visit Tri Nagar)



Index of Journals
February 13, 2011

I woke up early around 0630, watched n*de scenes from ‘Basic Instinct 2’ right in the morning. I watched ‘Social Network’ the fourth time after breakfast. It is an awesome movie. 
I needed earphones for that, and when I resolved to ask Anu for ear-phones, she made me feel like a beggar completely. Sh*t, I shouldn’t have ever gone for anything to her. Though later I got it from her only, I had even asked Srishti for it but that attempt was as useless as Srishti itself. 

I was giving my 2010 diary a finishing touch, and in the afternoon, I was sleeping. I had to write about the days of January of 2010 on laptop. 
Chachi would come and I will have to switch between windows, by the time it was night she had started to bang the door while leaving. It was probably because of that. 
Srishti came to ask for if I had taken any ear-phones from her room, I wanted to use abusive language for her but then I politely said ‘no’ to shoe her away fast. 

Amma and babaji had been to Tri Nagar today to attend some marriage. Amma had asked me to come but I refused due to shortage of time. 

God Bless ‘Me’
Ashish 

Thursday, September 16, 2021

Python (5): OOP Concepts



OOP Concepts

P: Polymorphism I: Inheritance E: Encapsulation A: Abstraction Apple PIE

How and where OOP concepts are used?

Because using classes well requires some up-front planning, they tend to be of more interest to people who work in strategic mode (doing long-term product development) than to people who work in tactical mode (where time is in very short supply).

The concept of “self”

class C2: pass # Make superclass objects class C3: pass class C1(C2, C3): # Make and link class C1 def setname(self, who): # Assign name: C1.setname self.name = who # Self is either I1 or I2 I1 = C1() # Make two instances I2 = C1() I1.setname('bob') # Sets I1.name to 'bob' I2.setname('sue') # Sets I2.name to 'sue’ print(I1.name) # Prints 'bob' There’s nothing syntactically unique about def in this context. Operationally, though, when a def appears inside a class like this, it is usually known as a method, and it automatically receives a special first argument—called self by convention—that provides a handle back to the instance to be processed. Any values you pass to the method yourself go to arguments after self (here, to who). If you’ve ever used C++ or Java, you’ll recognize that Python’s self is the same as the “this” pointer, but self is always explicit in both headers and bodies of Python methods to make attribute accesses more obvious: a name has fewer possible meanings.

Concept of Inheritance of Variables and Methods

class Employee: # General superclass def __init__(self, who = "NA", sal = 0): # Set name when constructed self.name = who self.salary = sal def getDetails(self): rtn = (self.name, self.salary) print("rtn: ", rtn) return rtn class Engineer(Employee): # Specialized subclass pass print("Defaults:") e = Engineer() e.getDetails() print() print("Custom:") e = Engineer(who = 'Ashish', sal = 100) e.getDetails() $ python inheritance.py Defaults: rtn: ('NA', 0) Custom: rtn: ('Ashish', 100)

Error Alert

class Employee: # General superclass def __init__(self, who, sal): # Set name when constructed self.name = who self.salary = sal class Engineer(Employee): # Specialized subclass pass e = Engineer() $ python inheritance.py Traceback (most recent call last): File "inheritance.py", line 14, in <module> e = Engineer() TypeError: __init__() missing 2 required positional arguments: 'who' and 'sal'

Polymorphism

class Employee: def __init__(self, who = "NA", sal = 0): self.name = who self.salary = sal def getDetails(self): rtn = (self.name, self.salary) print("rtn: ", rtn) return rtn class Engineer(Employee): def reviseSalary(self): self.salary =+ 100 def reviseSalary(self, inc = 200): self.salary =+ inc e = Engineer(who = 'Ashish', sal = 100) e.getDetails() e.reviseSalary() e.getDetails() e.reviseSalary(inc = 500) e.getDetails() $ python polymorphism.py rtn: ('Ashish', 100) rtn: ('Ashish', 200) rtn: ('Ashish', 500)

Abstraction

When we call "print()" for an object it prints some object details like these: <__main__.Employee object at 0x000001F549F7A1D0> However, when we define the Python's in-built __str__() for an object, we are essentially telling what should happen when print() is called for the object and end-user would not have to know how to get user-friendly details of the object. This is abstraction (abstraction of print()'s output in __str__() redefining it). class Employee: def __init__(self, who = "NA", sal = 0): self.name = who self.salary = sal def getDetails(self): rtn = (self.name, self.salary) print("rtn: ", rtn) return rtn class Engineer(Employee): def reviseSalary(self): self.salary =+ 100 def reviseSalary(self, inc = 200): self.salary =+ inc def __str__(self): # Higher priority than __repr__ when using with print() return '[From __str__: %s, %s]' % (self.name, self.salary) #def __repr__(self): # return '[From __repr__: %s, %s]' % (self.name, self.salary) e = Engineer(who = 'Ashish', sal = 100) e.getDetails() print("e:", e) print("e.__repr__():", e.__repr__()) f = Employee() print("f = Employee():", f) $ python abstraction.py rtn: ('Ashish', 100) e: [From __str__: Ashish, 100] e.__repr__(): <__main__.Engineer object at 0x000001F549C2F8D0> f = Employee(): <__main__.Employee object at 0x000001F549F7A1D0>
Tags: Python,Technology, Title: Python (5): OOP Concepts

Sunday, September 12, 2021

Anu's writing about mom (Aug-2021)



Index of Journals
06/Aug/21, 23:18 to 23:48
    
So my mother. I would start with her good things and her sincerity. 

She believes in god and she follows that religiously. May be she does not have many goals in life but she has given a Goal and a purpose to herself to follow Jainism. Sticking to her roots and her principles of religion is commendable. 

About her life, she was not from a very rich family but her parents gave her basic education like they gave to her siblings and it was her choice how she use that basic education. She could be a teacher. She could be a mother and pass on that education to her children. Or may be she could learn new things. When Amma who is 5th grade pass-out can make her kids engineers, lawyers, chatered accountants, then she could do that easily.
What Anu is not considering here is that dad was epileptic and had no income while grandpa was a lawyer.

Now the point is we don’t know her thinking. The bigggest thing in this universe is what a person thinks. 

She got married to a person who is not much capable but that lead her to a family where there are educated people and she was fortunate to get people like our grandparents in her life. I don’t think they can mistreat anyone (if they can be concerned about her even after knowing that she didn’t take care of their child. They can give love to anyone and everyone in this universe).

Wrong again. Life expectancy of an epileptic patient is more than 54 or 55 years of age. Dad did not get the best treatment. Anu complains what our mother has not done for us but did she ask herself what she did for our mother?

So yes she was fortunate to get into this family but how she used that opportunity?

Did she improved her life? 
Her life improved when I put a roof above her head. When I gave a house to live in.
Or she made it worse? She did not make it worse. You are making it worse by not recoginizing your reponsibilities towards your mother.

What was her thinking at that time?
What was she going through?

Have I asked her that - yes, I have but is she expressive and speaks her mind? No

Then how can I help her if she doesn’t speak what she thinks. How would I understand her character? 
You do not need to be an expert in character or personality identification in asking our mother is she needs anything.

But that was a time when I had no understanding about her and I could not judge her as kid. When I grew up and had my own senses. I could see and judge her.
Ashish to Anu: You are not in a positioin to judge her. You never will be. You have no right to judge anyone, let alone your mom.

But you know what when a person keeps on doing a thing and have same kind of thinking for a long time it builds a character - a new character. 

So someone might be a good person. But if that person constantly thinking negative doing negative and not working on building on a good character. They will turn into a negative person from a positive person.
Ashish to Anu: Stop doing character assassination of our mother.

And a negative person who constantly work on being a better human being will become a better person.
It’s about your choices in life.
Now back to her, I don’t know what she chose for herself. But what I know is she was monetary good, Babaji was helpful and she was getting food and house to live in. The basic necessities were given to her. 
Mom and dad were living the life of beggars, since what they were offered the least that could be offered.
Now her choice.

Can’t go back in time and change things but what I know is she is capable of doing things. She is capable of learning things.
Household women learn stiching, or doing embroidery or they teach tuitions or they make hand made things. And so many good things in this world to learn.

And if she can’t thibk of those on her own we can talk and give her ideas.
But again is she receptive? Is she willing to work? Is she ready to learn new skills? Utilise her time?
Ashish to Anu: She is doing good a rental property manager.

What is her thinking?
Thinking builds a character? What’s hers?
Ashish to Anu: Stop judging her character. You are neither in a position to judge nor you will ever be.

There are so many parents who lose their kids. There are wives who lose their husband. Don’t they survive?
Yes they do because they are willing to change their lives.
You are into blogging you must have read real stories about how a person builds their life.
How a handicap do things for his living?
But she has everything (by everything I mean her body and brain). 

Now it’s upto her what she thinks and how willing she is to use that for making her life better.
I don’t know her background and don’t want to know because there can not always be a good start to your life. But when do you start building a good life on your own is what matters.
She is not expressive therefore no one can help her. No person can help other person in this universe until you want to help yourself. People can push you to do good things but it’s your willingness to follow them or not.
Ashish to Anu: Today she is doing very well as a rental property manager. She has a working woman from a homemaker.

I live my life like I don’t have parents although she is alive. But do I crib and cry all the time when I see people getting so much from their parents and how their parents supporting them all the time? No I don’t . What I think is I am individual and my grandparents gave me education, humanity and principles and values. And no matter what in this life I will follow and try be a good human. It’s hard and it’s not easy with so many things going around and facing challenges. But that is what is going to make my life. 

I can be mad and angry and start drinking and drugs and fighting and make my life miserable. Is it in any way going to solve my problems?? 

To make my life better I have worked on the problems and my mindset.
So although she has children but she still can make her life better.
What is she doing for that ?
Ashish to Anu: She is a rental property owner and manager.

Tuesday, September 7, 2021

Functions in NumPy



The lists of NumPy functions are not exhaustive:

Unary
Binary
Commonly Used NumPy.LinAlg Functions
Tags: Technology,Python,NumPy,

Indexing in NumPy



Boolean Indexing
Tags: Technology,Python,NumPy,

Factorial, NumPy and DocTest



Script: s1.py

import numpy as np
import doctest 

def factorial(n):
    """
    Test for the factorial of 3 that should pass.
    >>> factorial(3)
    6

    Test for the factorial of 0 that should fail.
    >>> factorial(0)
    1
    """
    return np.arange(1, n+1).cumprod()[-1]

doctest.testmod() 

OUTPUT:


(base) CMD>python s1.py
**********************************************************************
File "s1.py", line 11, in __main__.factorial
Failed example:
    factorial(0)
Exception raised:
    Traceback (most recent call last):
        File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
        File "<doctest __main__.factorial[1]>", line 1, in <module>
        factorial(0)
        File "s1.py", line 14, in factorial
        return np.arange(1, n+1).cumprod()[-1]
    IndexError: index -1 is out of bounds for axis 0 with size 0
**********************************************************************
1 items had failures:
    1 of   2 in __main__.factorial
***Test Failed*** 1 failures. 


(base) CMD>python s1.py -v
Trying:
    factorial(3)
Expecting:
    6
ok
Trying:
    factorial(0)
Expecting:
    1
**********************************************************************
File "s1.py", line 11, in __main__.factorial
Failed example:
    factorial(0)
Exception raised:
    Traceback (most recent call last):
        File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
        File "<doctest __main__.factorial[1]>", line 1, in <module>
        factorial(0)
        File "s1.py", line 14, in factorial
        return np.arange(1, n+1).cumprod()[-1]
    IndexError: index -1 is out of bounds for axis 0 with size 0
1 items had no tests:
    __main__
**********************************************************************
1 items had failures:
    1 of   2 in __main__.factorial
2 tests in 2 items.
1 passed and 1 failed.
***Test Failed*** 1 failures.


Code with two functions

import numpy as np import doctest def factorial(n): """ Test for the factorial of 3 that should pass. >>> factorial(3) 6 Test for the factorial of 0 that should fail. >>> factorial(0) 1 """ return np.arange(1, n+1).cumprod()[-1] def isEven(n): """ Test that would pass >>> isEven(10) True Test that would fail >>> isEven(9) True Test that would pass >>> isEven(9) False """ rtn = n % 2 return rtn == 0 doctest.testmod() Output (base) CMD>python script.py ********************************************************************** File "script.py", line 11, in __main__.factorial Failed example: factorial(0) Exception raised: Traceback (most recent call last): File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run compileflags, 1), test.globs) File "<doctest __main__.factorial[1]>", line 1, in <module> factorial(0) File "script.py", line 14, in factorial return np.arange(1, n+1).cumprod()[-1] IndexError: index -1 is out of bounds for axis 0 with size 0 ********************************************************************** File "script.py", line 24, in __main__.isEven Failed example: isEven(9) Expected: True Got: False ********************************************************************** 2 items had failures: 1 of 2 in __main__.factorial 1 of 3 in __main__.isEven ***Test Failed*** 2 failures.
Tags: Technology,Python,Machine Learning,NumPy