Python v3.3.3 - don't understand how to make code work

A forum for general discussion of the Python programming language.

Python v3.3.3 - don't understand how to make code work

Postby meridius10 » Thu Feb 06, 2014 11:20 am

I just completed a Python course through codecademy and was using their own compiler for testing: http://labs.codecademy.com/#

I have now installed Python 3.3.3 on my Windows laptop but can't get the following code samples to work on the IDLE (Python GUI), although it works in codecademy's online complier. Any ideas?

Code: Select all
print "Welcome to Python!"


Code: Select all
def centigradeconverter(celcius):
    farenheit = (celcius * 9/5) + 32
    return farenheit
   
print centigradeconverter(25)


Code: Select all
pyg = 'ay'

original = raw_input('Enter a word:')

word = original.lower()
first = word[0]
new_word = word + pyg

if len(original) > 0 and original.isalpha():
    if first == 'a' or first == 'e' or first == 'i' or first == 'o' or first == 'u' :
        print new_word
    else:
        new_word = word[1:] + word[0] + pyg
        print new_word
else:
    print 'empty'
meridius10
 
Posts: 3
Joined: Thu Feb 06, 2014 11:01 am

Re: Python v3.3.3 - don't understand how to make code work

Postby stranac » Thu Feb 06, 2014 12:39 pm

That's python 2 code.
You need to install python 2 if you want to run it.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1218
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python v3.3.3 - don't understand how to make code work

Postby hrs » Thu Feb 06, 2014 3:20 pm

Or you could make a few minor modifications to run it with python3. As is, your farenheit calculation will only be correct for an input of 0 celcius because in python2, 9/5 = 1.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: Python v3.3.3 - don't understand how to make code work

Postby meridius10 » Thu Feb 06, 2014 3:44 pm

Oh wow, I've only just started and already this! I uninstalled Python 3 and installed 2.7.6. My first two code examples are working but not the 3rd. Any ideas?

I also noticed that if I put
Code: Select all
print ("Hello")
rather than
Code: Select all
print "Hello"
in Python 3 it works. What are the exact differences between the two versions?
meridius10
 
Posts: 3
Joined: Thu Feb 06, 2014 11:01 am

Re: Python v3.3.3 - don't understand how to make code work

Postby stranac » Thu Feb 06, 2014 3:49 pm

How does the third one not work?
Seems to work for me...

There are quite a few differences between python 2 and 3.
A few things that are different in python 3: print is a function, raw_input is renamed to input, strings are unicode by default, real division instead of integer division...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1218
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python v3.3.3 - don't understand how to make code work

Postby meridius10 » Thu Feb 06, 2014 10:07 pm

OK, thanks for the background. Still can't get my third code example to work. I'm not even getting a prompt so am not sure what it is.
meridius10
 
Posts: 3
Joined: Thu Feb 06, 2014 11:01 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 5 guests