Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 8th, 2013, 04:14 PM
 JENXPST
Registered User

Join Date: Jun 2013
Posts: 2
Time spent in forums: 4 h 43 m 10 sec
Reputation 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
June 8th, 2013, 09:05 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,213
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 4 m 30 sec
Reputation Power: 455
These remarks apply to python versions prior to python3

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!

#3
June 8th, 2013, 09:28 PM
 JENXPST
Registered User

Join Date: Jun 2013
Posts: 2
Time spent in forums: 4 h 43 m 10 sec
Reputation 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

#4
June 9th, 2013, 09:47 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,213
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 4 m 30 sec
Reputation Power: 455
You're using iron python?
Something's very very wrong and I really don't know how to help without sitting down beside you.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > New programmer help