Can you help (begginner) Python


#1

a = raw_input (“1º numero”)
b = raw_input (“2º numero”)
maximum = max(a,b)

print maximum

Whats wrong with this code in python 3
Because there’s always a error in “print maximum” but whaen i put in python 2 there isn´t that error anymore
Can you help me?


#2

print is a function, not a construct in Python 3. Must have ().

raw_input is undefined in Python 3. Use input.

a = input("First number")
b = input("Second number")
print (max(a, b))

#3

And can I do like this:

a = input(“First number”)
b = input(“Second number”)
print (“The greater number is %s”) % (max(a,b))

to appear “The greater number is X”


#4

We cannot break up the format string and its arguments. It should all be inside the print parens.

print ( ... )

as in,

print (“The greater number is %s” % max(a,b))

Python 3 offers a new and more flexible format method…

print (“The greater number is {}”.format(max(a,b)))

#5

Thanks man.
I didn´t know that because I’m taking the free codecadamy course about Python and it’s in Python 2


#6

Okay, then stick to Python 2 syntax. You can still use the Python 3 print () statement so build on the habit of using the parens. It shouldn’t affect your lessons (but if it does, then remove the parens).

In Python 2, use raw_input() for string inputs.