ICP1 Explanation - acvc279/Python_ICP1 Wiki

Welcome to the Python_ICP1 wiki!

Question 1: State differences between Python 2 and Python 3 version.

  1. In python 2, parentheses of a print function is not required but in python 3 parentheses of print function is mandatory.
  2. In python 2, the global variable will change when we use it inside the loop but in python 3 the variable value never changes.
  3. To perform iterations, range() is used in python 3 whereas xrange() is used in python 2.

Question 2: Input the string “Python” as a list of characters from console, delete at least 2 characters, reverse the resultant string and print it.

At First, we are going to input the string to a variable a. After that, By using slicing function we delete the two characters and then reverse the string. Now, we assign the modified string to a previous variable and we print variable a.

Take two numbers from user and perform arithmetic operations on them.

we are going to input the two integers values to a two different variables. And then we print the variables with input values. Here we are performing and printing the arithmetic operations like addition, Subtraction, Multiplication, Division.

Queston 3: program that accepts a sentence and replace each occurrence of ‘python’ with ‘pythons’ without using regex.

At first, we are going to input the sentence with python occurrence and then by using replace function we replace python to pythons. We print the replace function.