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,910 points
928 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,300 points

Related Questions In Python

0 votes
3 answers

Is python version 3.7.2 supported by pycharm jetbrains IDE?

Yes it works fine.. READ MORE

answered Feb 28, 2019 in Python by Pratosh kumar
1,393 views
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, 2019 in Python by Priyaj
• 58,020 points
3,375 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, 2019 in Python by Varsha
34,536 views
+1 vote
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, 2019 in Python by Arvind
• 3,050 points
9,302 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,443 views
0 votes
1 answer
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,300 points
2,331 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, 2019 in Python by SDeb
• 13,300 points
2,748 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP