How is Python 2.7.3 and Python 3.3 different?

0 votes

What are the changes required for the same code written in Python 2.7.3 before and now it needs to be executed in Python 3.3?

The code is :-

nm = input(“enter your name “)

str = raw_input(“enter ur details: \n”)

f = open(nm,”w”)

f.write(str)

f.close()

print 1.See the file\n

print 2.Exit\n

s = input(“enter ur preference “)

if s == 1 :

   fi  = open(nm,”r”)

   cont  = fi.readlines()

for i in cont:

    print i

else :

    print thank you, goodbye  


Please point out the changes to be made so that it runs without any error in Python 3.3
Sep 12, 2018 in Python by ana1504.k
• 6,710 points
28 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
  • raw_input() is not used in Python 3. Use input()  function such as-

    str = input("enter ur details: \n")
  • input() cannot evaluate the value it parses in Python 3. for that you need to use eval(input()) such as :

    s = eval(input("enter ur preference "))
  • print() is a function in Python 3 but it was a statement in Python 2. so it need to be called in the following way:

    print("1.See the file\n")
    print("2.Exit\n")
    
    print(i)
    
    print("thank you, goodbye")
answered Sep 12, 2018 by SDeb
• 10,860 points

Related Questions In Python

0 votes
3 answers
0 votes
1 answer

How to change python version into 3.7.2 for entire pycharm jetbrains IDE projects?

Navigate to the Project page, select the configured interpreters ...READ MORE

answered Feb 27 in Python by Priyaj
• 56,140 points
33 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 66,910 points

edited Aug 8, 2018 by Omkar 330 views
+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 56,140 points
92 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 views
0 votes
1 answer

How to install OpenCV for Python 2.7?

The official OpenCV installer does not install ...READ MORE

answered Nov 14, 2018 in Python by SDeb
• 10,860 points
58 views
0 votes
1 answer

Bash alias --> Python 2.7 to Python 3.3

Some linux utilities depend on python2.x currently. ...READ MORE

answered May 9 in Python by SDeb
• 10,860 points
13 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.