Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105184
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Terry Reedy <tjreedy@udel.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: Beginner Python Help |
| Date | Fri, 18 Mar 2016 03:20:49 -0400 |
| Lines | 38 |
| Message-ID | <mailman.303.1458285656.12893.python-list@python.org> (permalink) |
| References | <101edd27-17e1-497c-a60f-fa56b033563b@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de iYbbT4brOZUePO0FkV2CrAM48FLhrrW6yR/+Q4qt7+Lw== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'jan': 0.11; 'code?': 0.16; 'list1': 0.16; 'map(int,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'string': 0.17; 'input': 0.18; 'hey': 0.20; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; '(e.g.': 0.27; 'compare': 0.27; 'alan': 0.29; 'strings,': 0.29; 'convert': 0.29; 'raise': 0.29; 'problem': 0.33; 'list': 0.34; 'done': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'there,': 0.37; 'received:org': 0.37; 'doing': 0.38; 'wrong': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'maximum': 0.61; 'skip:n 10': 0.62; 'received:96': 0.63; 'gabriel': 0.84; 'min': 0.91; 'received:fios.verizon.net': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | pool-96-227-207-81.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <101edd27-17e1-497c-a60f-fa56b033563b@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:105184 |
Show key headers only | View raw
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