ICP1 - PardhaSaradhi74/Python GitHub Wiki

1. State differences between Python 2 and Python 3 version. ANSWER)Differences between Python2 and Python3? Library:

In python2,Many older libraries built for Python2 are not forwards-compatible. In python3,many of today’s developers are creating libraries strictly for use with python3

ASCII

In Python2,strings are stored as ASCII by default whereas in Python3, text strings are Unicode by default.

Print Syntax

In python2,The print syntax is treated as a statement rather than a function which requires text wrapped in parenthesis. In python3,The print is explicitly treated as function and replaced by the print() function which requires extra pair of parenthesis.

Dividing two integers

In Python2,It simply returns an integer to the nearest whole number whereas in Python3 it makes more intuitiv by using true division for integers and floats.

Xrange function

In python2,xrange function reconstructs the sequence everytime and in python3 it is replaced by range()

2. Write a python program for the following:–Input the string “Python” as a list of characters from console, delete at least 2 characters, reverse the resultant string and print it.Sample input:•python•Sample output:•ntyp

ANSWER)In this program,I provided user by taking the text from keyboard.For suppose if you give python it removes two letters and reverses the string

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

ANSWER)In this programs user enters two integers and once those are given it performs mathematical operations like addition,subtraction,multiplication,division.

3.Write a program that accepts a sentence and replace each occurrence of ‘python’ with ‘pythons’ without using regex•Sample input:•I love playing with python•Sample output:•I love playing with pythons

ANSWER)In this program user provides a sentence.For suppose if you give 'I love playing with python' it replaces 'python' with 'pythons'