ICP_2 - acvc279/Python_Deeplearning GitHub Wiki

Q1: Write a program, which reads height(feet.) of N students into a list and convert these heights to cm in a separate list

First we are going to creating an two empty lists(naming as list and l) for storing heights and cm later, then we are going to input the no. of students. Now input the values(height in feet) to the list by using for loop(inside the loop use append function for adding i/p values) and print the list. Now we are converting the list from feet to cm by using logic inside the for loop and stored the values in l(list) ten print the list.

Q2: Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.

first we declare and initialize step to zero then input the value through user and initialize to variable a. After that we find odd and even number under the while loop and the loop has logic that if the no. is even then it should be divided by 2 else it would substracted by 1. By doing these process we count the all iterations of while loop and stored the count in variable step then print the step to get the output.

Q3: 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.

First we open the file in read mode and create an empty dictionary. Now we use for loop to each line in the file and we use strip function and split function to remove spaces and split the words from sentence. using for loop we are going to count each word in sentence and check the word in directory and if it found again increment count again. now print the no of words with count by using dictionary. Now we add our output to the same text file. Again we open the file in append mode then we append the values into sample text file here only string are allowed to append so we are converting values to string to write in file after stored the output to file close the file using close function.

VIDEO LINK: https://drive.google.com/file/d/1uFM2hihjlPrabd7PB7x3xFKrOSGeuXaL/view?usp=drivesdk