Wiki Report for ICP2 - NagaSurendraBethapudi/Python-ICP GitHub Wiki

Video Link : https://drive.google.com/file/d/15zmRtKdYEp0NQRhuFKRBwd3-h155XtOi/view?usp=sharing

Question 1:

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

Explanation:

  1. Requested input for number of students from console
  2. Requested height of students
  3. Converted the height of students from feet to cms using below logic:
    • studentsHeightinfeet.append(students) #appending all the students height in feet into a list
    • L=[float(i)*30.48 for i in studentsHeightinfeet] #1 feet = 30.48 cms
    • studentsHeightincms.append(L) #appending all the student height in cms into a list

Question 2:

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

Explanation:

  1. Requested input for non - negative number
  2. Found the steps to reduce it zero using below logic:
  • while Number > 0:
      if Number % 2 == 0:           #checing the number if it is divided by two or not (Even Number) 
          Number = (Number // 2)
          count = count + 1
      else:
          Number = (Number - 1)    #odd number
          count = count + 1
    

Question 3:

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

Explanation:

Completed this program in two ways

Type 1:

  1. Using Counter -- By using this we can find key value pairs.
  2. By checking word in word.counter, we can find the word frequency.

Type 2:

  1. Initially the characters in line are lowered and spaces are removed
  2. Now by using for loop we are comparing the each word against the words in dictionary and appending the count

Conclusion :

  1. We learned how to convert the values in a list and pushing them into a another list.
  2. In class i got to know more info about loops, lists, functions and a sample program about car rentals using functions and loops.

Challenge:

  1. Question 1 and Question 2 are bit easy , in question 3 i spent more time on how to store the output back to input file.