python icp 2 - koushikskr/python GitHub Wiki

Question 1:

Write a program, which reads weights (lbs.) of N students into a list and convert these weights to kilograms in a separate list

steps:

Enter the weights of students separated by space

Split each student weight from user.

Append all the student weights into a list created.

Loop through each weight and convert it into kilograms.

Print the final list

Question 2:

Write a program that returns every other char of a given string starting with first using a function named “string_alternative”

steps:

Create a main function and read input from the user.

Create a method called “string_alternative and pass the input string to it.

In the created method definition, print the alternative characters from the string using string slice.

Question 3:

Write a python program to find the word count in a file for each line and then print the output.Finally store the output back to the file.

steps:

Read input file in read mode. Create a dict object and store it in d Get the contents of the file into a string. Split the string and put in words list Loop each line and word using d Get all the keys and print the word count