Simple Python Quiz - 01

01. Store four file objects corresponding to the files winter2003.txt , spring2003.txt, summer2003.txt, and fall2003.txt in the variables  winter, spring, summer, and fall (respectively), and open them all for reading.

winter = open('winter2003.txt','r')
spring = open ('spring2003.txt','r')
summer = open('summer2003.txt','r')
fall = open('fall2003.txt','r')


02. Write a statement to open the file yearsummary.txt in a way that erases any existing data in the file.


open('yearsummary.txt','w')



03. Given a file named execution.log write the necessary code to add the line "Program Execution Successful" to the end of the file (add the statement on a new line).


f = open('execution.log','a')
f.write("\nProgram Execution Successful")



04. Given that corpdata is a file object used for reading data and that there is no more data to be read, write the necessary code to complete your use of this object.

corpdata.close()


05. Use the file object output to write the string "3.14159" to a file called pi.

output = open('pi','w')
output.write('3.14159')




To be Continuted...

Getting String character by Character in bash

Sometimes you may need to get string character by character or need to looping through the string. In python programming language, you can do this job very easily.

See below example in python.

your_string="Hello"
for c in your_string :
        print (c)

This will give output as,

H
e
l
l
o


We can do same thing in bash shell scripting also,

see below bash shell scripting example.

#getting ord value of chars.
your_string="Hello"
echo $your_string | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | \
while read char
do
echo $char
done


Cheers.... ! Happy looping through the string !

Functions for ord and chr in bash shell scripting

In python there are couple of useful function. these are ord function and chr function.

ord function in python - it take character as an argument and return its ASCII value.

chr function - it takes integer values as an argument and returns character that is equivalent to the integer value.

I am going to introduce function to do same thing in bash shell scripting. I named it as ord.

ord() {

  LC_CTYPE=C printf '%d' "'$1"
  return $LC_CTYPE

}



My next function is chr function. it takes integer value as an argument and returns correspponding ASCII value.

chr() {
  [ "$1" -lt 256 ] || return 1
  printf "\\$(printf '%03o' "$1")"
}

My Life as a Systems Engineer

I am a Bsc. Engineering graduate in Computer Engineering who has acquired  expert knowledge in developing systems under Linux platform. I have gained 4+ years of experience in doing shell scripting, awk scripting, python, and java developing. I am professionally qualified in CCNA.

Working was fun as well as challenging day by day, where I invited most of the challenges to my life. Time to go to bed and time to wake was not according to the clock but according to the work which are pending or to find a new thing every day. It can be twelve clock in the midnight or twelve clock in the day time I was in front of the laptop programming code.


Freelance working has kept me in a high place which I took the membership in November having a good response rate, not cancelling any orders where my buyers has graduated me for Level 1.


Q6 : If you are the HRM of this company how can you prevent such scenarios?

See this post for Whole Question. 



Q6: If you are the HRM of this company how can you prevent such scenarios?

To achieve the set goals and objectives of the organization the human resources which play the major role in an organization should be managed and used in an efficient and effective way. Human resource management impact employee behavior, attitudes, performance, intelligent, skills and knowledge. The labor within the organization should be managed according to philosophies, politics, procedures and practices of Human Resource Management to get the maximized economic return from labor resources by decreasing the wastage of materials and equipment. The human resource management in an organization should be done by experts or a specially qualified person for benefits otherwise it will more lead to more strict rules and regulations and only managers people not thinking that the people are a resource which can be developed and trained to retrain for a long period of time which will be very advantageous for the company’s future. HR manage always make sure the workers that they are not doing a job but it is their own career and help them grow and develop by themselves.

The HR manager should be like honey in a Bee hive where all bees get together in making the Bee hive using honey and if there is anybody doing harm all the bees get together in protecting the Bee Hive. Likewise the workers will be willingly to work towards the productivity and future of the company when HRM is integrated into business strategy. The HR Manager should be fair to all employees at any level, cooperative and always should give a helping hand for the employees in their work. He should lead the workers administrate the internal functions such as checking the attendance of workers, organizing trainings depending the training needs of the organization. He should strategically win the good will of the employees and counsel workers. He should change systematically for different situations in order to maintain the flexibility for the employees to approach. If the HRM is not integrated property it will cause high rate of resignations within a short period of time.

The motivation and interest of the employees will be a poor the employees will criticize the organization always and there will be a loss in the output.

In the case study of MR. Kamal an effective and efficient HR Manager is the first person to realize the stress that which Kamal is undergoing. He is getting absent frequently and behavior has changed when working. As a first step the HR Manager discuss about this with Mr. Kamal and understand the situation of unwillingness to report the work. He will analyze the problem and arrive at conclusions to be discussed in three different aspects. One aspect is the Management and Mr. Kamal. He is facing difficulties with the policies, rules and regulations which newly introduced or weather he needs increments, bonus, promotion or an appreciation for his 20 years of service. HR Manager should understand which one of the following be the cause and must take immediate actions having discussions with the Management. Another aspect is the sub-ordinates of Mr. Kamal. Those who are in the same level as Mr. Kamal weather they are cooperative, team work or weather the juniors make troubles for him. The HR Manager can advise them informing about the situation of Mr. Kamal to be more friendly and polite to him. One the other hand may be he is unable to carry out the duties with the new technologies or else he needs special training to carry out work. So the responsibility of HR Manager is to send Mr. Kamal for suitable trainings so that he is conversant with his work. May be his change of position as for 20 years he was handling the same correspondence and it has become boring. So HR Manager can discuss with the managers and can help to look forward changing positions. If it is his mental ill health that he is facing the stress he can be granted some leaves to take SOME and come back to work with a refreshing mind.