ICP 2 - AsharGit/Python-ICP GitHub Wiki

Welcome to the Python-ICP-2 wiki!

For this ICP we used lists, loops and file input/output in Python. The ICP was divided into 3 tasks.

Video for this ICP: https://youtu.be/1uOLyBE9Puk

The first task asks us to write a program that can take input heights from user in feet. Add it to a list and then convert from feet to cm and add it to a new list. For this task I used while loop, lists, and list comprehension. Here is the code:

Code

The output:

Output

The second task asks us to receive a non-negative number from user and then reduce it to 0 using division by 2 for even numbers and subtraction by 1 for odd numbers. Once completed report to the user how many steps it took to get down to 0. For this task I used while loop to complete operations on the input number until I got to 0. Here is the code:

Code

The output:

Output

The final task asks us to read a text file and to make a total of specific word count. Print the result to console and add the result back to the text file. For this task I used for loop and file read, split, and append functions. Here is the code:

Code

The output:

Output

Here is what the text file looked like before and after running the code:

Before After