Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105184
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Beginner Python Help |
| Date | 2016-03-18 03:20 -0400 |
| Message-ID | <mailman.303.1458285656.12893.python-list@python.org> (permalink) |
| References | <101edd27-17e1-497c-a60f-fa56b033563b@googlegroups.com> |
On 3/18/2016 3:04 AM, Alan Gabriel wrote:
> Hey there,
>
> I just started out python and I was doing a activity
> where im trying to find the max and min of a list of numbers i inputted.
>
> This is my code..
>
> num=input("Enter list of numbers")
input returns a string
> list1=(num.split())
list1 is a list of strings
> maxim= (max(list1))
> minim= (min(list1))
min and max compare the strings as strings, lexicographically
> print(minim, maxim)
>
> So the problem is that when I enter numbers with an uneven
> amount of digits (e.g. I enter 400 20 36 85 100)
> I do not get 400 as the maximum nor 20 as the minimum.
> What have I done wrong in the code?
You failed to convert strings of digits to ints. Try
list1 = map(int, num.split)
This will raise TypeError on strings that cannot be converted.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Beginner Python Help Alan Gabriel <alanunny@gmail.com> - 2016-03-18 00:04 -0700
Re: Beginner Python Help Terry Reedy <tjreedy@udel.edu> - 2016-03-18 03:20 -0400
Re: Beginner Python Help Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-18 09:44 +0200
Re: Beginner Python Help Chris Warrick <kwpolska@gmail.com> - 2016-03-18 08:23 +0100
Re: Beginner Python Help Ben Finney <ben+python@benfinney.id.au> - 2016-03-18 18:26 +1100
Re: Beginner Python Help "Martin A. Brown" <martin@linux-ip.net> - 2016-03-18 00:50 -0700
csiph-web