Today,we spent some time with the children in an orphanage. Our visit to an orphanage is a life changing experience. This is the moment when I actually started appreciating the little things in life.
We were lucky to get an opportunity to visit an Orphanage named Mamta Foundation ( a project for the welfare of HIV +ve children and women). There were about 35 children right from the age group of 6 to 18,5 caretakers,and a couple who are in charge of the entire place. They live in a Bunglow at Kondhwa in the Pune city, Maharashtra state, India.
We reached in the morning at the location.After we entered we got to know about the foundation like when it was started and what all programmes it conducts for the welfare of the children there, by the woman in charge of the place.
We had brought fruits,books,pen,etc.with us. We segregated ourselves and then talked individually to everyone. We interacted with the children and played games(Dam-sharas).
After interacting with them we are happy to found that the children there are so active talented and happy. Girls there have multiple talents like singing,dancing,making handmade jewelry,painting.
It was very good experience with full of emotions. Today, I learnt a lesson that you should always be thankful for your family. Not everyone is fortunate like us. Today I am greatful for the life and education I have.Suddenly,assignments and exams don’t sound too bad to me. 🙂
Lets take a problem statement stating : Take a LIST of integers and find SUM of the numbers of the list.Suppose that you want to calculate the sum of a list of numbers such as: [1,2,3,4,5].In normal mathematical form,we might have solve this problem by using the addition rule of adding a pair of numbers.We might have converted the list into fully parenthesized expression
and solved it using parenthesis rule to get the total of 15.
Now think how can we solve it using a python program?We can solve it using two ways.
for i in list1:
The function uses variable
theSum to get total of all the numbers in the list by starting with 0 and adding each number in the list.
if len(list1) == 1:
return list1 + listsum(list1[1:])
This is a recursive algorithm.Here list1 is the sum of the first element of the list (i.e list1) and the sum of rest of the numbers in the list(i.e list1[1:]).
In the code,in line 2 we are checking if the list contains only one element.This is necessary to check because by knowing this we can escape from the function.The sum of the list containinig only one number is the number in the list.
On line 5 of the code function calls itself.This is called recursive function.A recursive function is a function that calls itself.This makes our code more simple.
PyLadies October Meetup was held at Red Hat India Pvt. Ltd., Pune on 20th October,2016. This was my first python meetup. Many people from different colleges attended the meetup. The topic for the meetup was “Create your own shell using Python”.
The meetup started with the talk by one of the founders of FOSSASIA Dang Hong Phuc on how “FOSSASIA meets Pyladies Pune”. She briefed us about FOSSASIA by saying that FOSSASIA is a non-profit organization supporting developers and makers of Free and Open Source technologies. She encouraged the belief of improving women participation in open source. Her talk was very encouraging and helpful.
Then there were few more talks from the pyladies Samriddhi and Pooja explaining there journey with python. Samriddhi talked about her projects in python. And Pooja explained the difference between python2 and python3.
At the end of this meetup there was workshop on “Create your own shell using Python” by Kushal Das. In this workshop Khushal taught us how to use the cmd2 module of python to build our own command line interpreter(CLI).
Code to create shell using python:
Some of the Important point from Code:
- from cmd2 import Cmd : cmd2 is a python package for building powerful command-line interpreter (CLI) programs. Extends the Python Standard Library’s cmd package.
- We created a subclass of cmd2 REPL. Define do_* methods to control its behavior.
- prompt:We created our own prompt i.e.pyladies.Here prompt is a inbuilt variable of cmd2 issued to solicit input.
- __init__ is the constructor for a class. The self parameter refers to the instance of the object.The __init__ method gets called when memory for the object is allocated.
- def do_hello(self, line):If we use hello command with one argument (as shown in ouput ) I used hello pyladies is giving output as pyladies in red color.The command method always takes the argument, but sometimes the value is an empty string. It is left up to the command processor to determine if an empty argument is valid, or do any further parsing and processing of the command. Text output can be colored by wrapping it in the colorize method.
- def do_uid(self,line):On typing the command uid on terminal we get output current process’s real user id.and User home directory.In this function we used various inbuild functions in python like getuid(),getpwuid(uid) .In order to use these function we have to import os and pwd modules of python.
- os.getuid():Return the current process’s real user id.
- pwd.getpwuid(uid):Return the password database entry for the given numeric user ID.
- .pw_dir:User home directory.
- if __name__==’__main__’:__name__ is global variable in Python.Every module in python has a special attribute called __name__ . The value of __name__ attribute is set to ‘__main__’ when module run as main program.
Lastly, I want to say that it was worth and fun attending the meetup.Thanks pyladies pune.:)
Looking forward to attend the next meetup.