ICP 2 - awais546/Python-and-Deep-Learning GitHub Wiki
Python and Deep Learning
Introduction
In this ICP we learned about different control statements and their use by applying it in different practical examples. The ICP consists of three questions each focusing on a different control statements.
Tasks
Following are the tasks.
- Convert the list containing values in "Feet" to centimetres
- Return the number of steps to convert a non-negative number to zero
- Read a file and return the number of count of each word
Question 1:
In Question 1 I took the input for the number of students and iterated for each student using a for loop to make a list of height in feet. Then I created a function which takes the input list as an argument and convert each height into centimetres by multiplying each value with 30.48. Following screenshot shows the function.
Following is the result of the function
Question 2:
In Question 2 I took a non-negative number and sent it to a function that returns an integer showing the number of steps to convert the corresponding number to zero. I used a while loop checking if the number has become zero or not. If the number is even then divide it by 2 else subtract 1 from it. Following screenshot shows the function.
Following screenshot shows the output of the function.
Question 3:
In Question 3 I read an input text file containing some text. The function wordCount will take the input file as input and iterate over each line using a for loop. There is another nested for loop that split splits each line into single word. An empty dictionary will save each word as a key having the initial value as one. If the number is repeated then the value is increased by one. Following screenshot shows the funciton.
Following screenshot shows the result of function