Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Warrick Newsgroups: comp.lang.python Subject: Re: Beginner Python Help Date: Fri, 18 Mar 2016 08:23:54 +0100 Lines: 42 Message-ID: References: <101edd27-17e1-497c-a60f-fa56b033563b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de BZ11OzLVdWnDE35z9u8LigKZL+ChAs08gXWWLdKdkjOA== Return-Path: 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; 'cc:addr:python-list': 0.09; 'assigning': 0.09; 'subject:Help': 0.10; 'python': 0.10; '2016': 0.16; 'code?': 0.16; 'galaxy': 0.16; 'integers.': 0.16; 'list1': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'variables:': 0.16; 'wrote:': 0.16; '<': 0.18; 'comparing': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; 'variable': 0.18; 'hey': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; 'trying': 0.22; 'cc:no real name:2**0': 0.22; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'earlier': 0.27; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'strings,': 0.29; 'problem': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'something': 0.35; 'received:74.125.82': 0.35; 'subject:: ': 0.37; 'there,': 0.37; 'doing': 0.38; 'wrong': 0.38; 'where': 0.40; 'maximum': 0.61; 'skip:n 10': 0.62; 'mar': 0.65; "'2',": 0.84; '(also,': 0.84; 'min': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=gNVKs6mnMM7Lp/EaWAVw407utrCjokTPYzH0rnZtwL8=; b=liCNnaYPhKr3QyhM59lrPSKQkdnmtabCpo1hbZqilqeaQFJXqAB6NRoDaqPCz/T8dw hYLeVytpPd15CjovNAoE1hxEXlggfaJTh4GsUmj34i/qjgv0cZCW68KFVbULQTkkvDpU ArshJ9VAcMcGRAWGibLieCpl8GQLJWygacFxSlJm8Ytp4CZp0qm+kZmHb9YVlWF+FCkM I2ZskgE8KH7abYcEtnVFcXRCeIggWvTIExmzckuhHs57n4XQ0c13TKq3226kEt1bDtDU EnGam/qqOvL40eP2a20Na3IMZBU+kPTPjSIk/Zxp7yx6fmgJENPH6EYp88yGiXVE+f6K OhFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=gNVKs6mnMM7Lp/EaWAVw407utrCjokTPYzH0rnZtwL8=; b=WG+HZG9+toikIZlTvbSo6PPsLE+E08LbHqR2pfEtCoicN5NHfn/IYbkpRd+mK3Xe0u dtgcQv5VnmkTB6fS+7NP7WtJkPVOto9Bn2by0e95rsd0FoFIVNJ0Rdz7T3mT37bFfH1y cjhDFL0GkI1/iOQru/GMktKt5CRmRCWg0VW6FmJ/v7CmjLj2xR3Aoh7A25CQeWomLrWZ snG8LSYTjkXTGgtZNsqwj65QRnGkEkCazCNX4xxnwppUSnpfRSTDaA1lLV7XHheYOLQL aJqqXJNdO8l66mwCV8dvxN1ghTqM06jD2vYfL2OcqSzCi6EuQXPxVBv75VnalT1e74tG jb2g== X-Gm-Message-State: AD7BkJKodKZafrOyIcJAdO46uAzoTB0qsh2X2vwwJ/+/aCILxFNtQNr89sKqckLtTHm4ZY3cZzVN6ACSQCgajw== X-Received: by 10.194.9.34 with SMTP id w2mr14106880wja.170.1458285834186; Fri, 18 Mar 2016 00:23:54 -0700 (PDT) In-Reply-To: <101edd27-17e1-497c-a60f-fa56b033563b@googlegroups.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105185 On 18 Mar 2016 08:05, "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") > list1=(num.split()) > > maxim= (max(list1)) > minim= (min(list1)) > > 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're dealing with strings (text) and not integers. And when comparing strings, '1' is earlier than '2', thus '100' < '20'. To fix this, you can use a list comprehension: list1 = [int(i) for i in num] You also don't need (parentheses) around functions when assigning to variables: maxim = max(list1) minim = min(list1) (Also, list1 is not a good variable name. Try something that describes its contents.) -- Chris Warrick Sent from my Galaxy S3.