ICP2 - PardhaSaradhi74/Python GitHub Wiki

Q1)Write a program, which reads weights (lbs.) of Nstudents into a list and convert these weights to kilograms in a separate list using:1) Loops and2) List comprehensionsN: No of students (Read input from user)Ex: L1: [150,155, 145, 148]Output: [68.03, 70.3, 65.77, 67.13]

Answer)In this program i took the number of students into listthat need to convert and then take the inputs from user in lbs and appending those items into list and finally performing the weights from lbs to kg

2)Write a program that returns every other char of a given string starting with first using a function named “string_alternative”Str = “Good evening”Output: Go vnnNote: You need to create a function named “string_alternative” for this program and call it from main function. Ans)In this program i am creating a function string_alternative.The user was provided with entering a string and when we call the function it randomly deletes characters in the string and gives the output.The corresponding output is shown in the picture below.

3)Write a python program to find the wordcountin a file for each line and thenprint the output.Finally store the output back to the file.Input:a file includes two linePython CourseDeep Learning Course Output:Python: 1 Course: 2 Deep: 1 Learning: 1 Note: Your program should work for any number of lines.

Here I opened a file in read mode which is text file then declared an empty dictionary and read each word from the file where I checked if that word exists if so then incremented the count if not then added the word to dictionary and at end took all keys and values which are converted as string from dictionary and printed to console then opened the file in append mode to write down the results to file and at end closed the file screenshot is attached below.