#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    New programmer help


    I am trying to write a program in which I ask the user to type in three numbers from the terminal and then output (to the terminal) the maximum of the three numbers. This is what I have so far:

    x = raw_input("Type three numbers: ")
    print "The maximum of the three numbers is: ", max(x)

    When I run the program, the question pops up for me to enter three numbers like I want it to. I then enter three numbers, for example I have been using 3, 7, and 24. Once I click enter for it to pop up the max of the three, I get the message that says "
    The maximum of the three numbers is" like I want it to but it keeps saying 7 is the max. Can anyone help me fix it so it will give me the correct max.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    These remarks apply to python versions prior to python3

    Try your program like this:

    x = input("Type three numbers: ")
    print "The maximum of the three numbers is: ", max(x)


    raw_input returns a string. The maximum ASCII code of your string, character by character, is that of '7'.

    Using max on a string might be applicable to this problem.


    input , on the other hand, evaluates the information entered as a python expression. 24,7,2 is a tuple with maximum 24, as you expect.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    When I use input instead of raw_input, this is the error it gives me:

    %run "c:\users\leeanna\appdata\local\temp\tmpta9zmu.py"
    Type three numbers: ---------------------------------------------------------------------------
    EOFError Traceback (most recent call last)
    C:\Users\Leeanna\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.0.0.1160.win-x86\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
    174 else:
    175 filename = fname
    --> 176 exec compile(scripttext, filename, 'exec') in glob, loc
    177 else:
    178 def execfile(fname, *where):

    c:\users\leeanna\appdata\local\temp\tmpta9zmu.py in <module>()
    ----> 1 x = input("Type three numbers: ")
    2 print "The maximum of the three numbers is: ", max(x)

    EOFError: EOF when reading a line
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    You're using iron python?
    Something's very very wrong and I really don't know how to help without sitting down beside you.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo