Home - koushikskr/python GitHub Wiki

Welcome to the python wiki! Stating the differences between Python 2 and Python 3 version. Differences between Python 2 and Python 3:

  1. Print function Syntax:

In Python 2, no need of parenthesis, where as in Python 3 parenthesis are must.

  1. Division Operator:

In python 2, result will be nearest whole number.

7/5=2

In python 3, result will be float.

7/5=1.4

  1. String type:

In Python 2, default string type is ASCII. In Python 3, default String type is Unicode.

Question2 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.

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

Code:

a = int(input('Enter First number: ')) b = int(input('Enter Second number: ')) add = a + b dif = a - b mul = a * b div = a/b

print('Sum of ',a ,'and' ,b ,'is :',add) print('Difference of ',a ,'and' ,b ,'is :',dif) print('Product of' ,a ,'and' ,b ,'is :',mul) print('Division of ',a ,'and' ,b ,'is :',div)

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

Code: string = input('enter string'); result = '' for i in string: if i == 'n': i = 'ns' result += i print(result)