ICP 1 - Saiaishwaryapuppala/CSEE5590_python_Icp GitHub Wiki

Python and Deep Learning: Special Topics

Rajeshwari Sai Aishwarya Puppala

Student ID: 16298162

In class programming:1

Objectives

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

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

  • Sample input:python

  • Sample output:ntyp

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

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

Differences between python 2 and 3

Python2

  1. Started in mid 2010

  2. Integer division 5/2=2

  3. Print statement ex: print "hello"

  4. It uses xrange and range functions

  5. Here raw_input returns a string and input() tries to run the input as a python expression

Python3

  1. Started in early 2014

  2. Integer division 5/2=2.5

  3. Print statement ex: print ("hello")

  4. It has no xrange function

  5. Here input() returns a string always

Deleting at least 2 chars and Reverse the string

CODE

  • Reverse string function is called
  • Input is taken from the console
  • last and last but second chars are removed (remove function is called)
  • Reverse the string by calling reverse function

Output

Arithmetic Operations

Code

  • Take 2 numbers from the console
  • Call the arithmetic operation functions i.e add, subtract, multiply, divide

Output:

Output

Replacing python with pythons

Code:

  • Take the string from the console
  • convert into lower case
  • Replace the "python" with "pythons" by using replace method

Output: