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
• 7,870 points
34 views

1 answer to this question.

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
• 13,160 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,520 points
56 views
0 votes
1 answer

How do I upgrade my pycharm from python 2.7 to python 3?

Install Python 3.7(latest version) from the following ...READ MORE

answered Aug 5 in Python by Varsha
50 views
0 votes
1 answer

How to install tensorflow using anaconda and python 3.7.1 on windows?

Since I am using python 3.5 so ...READ MORE

answered Aug 19 in Python by Arvind
• 2,960 points
60 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 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
• 13,160 points
87 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
• 13,160 points
71 views