Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'yet.': 0.04; 'smallest': 0.07; 'subject:code': 0.07; 'variables': 0.07; 'subject:help': 0.08; 'imply': 0.09; 'learn,': 0.09; 'main()': 0.09; 'oh,': 0.09; 'spaces': 0.09; 'subject:trying': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '3:27': 0.16; 'assigns': 0.16; 'code?': 0.16; 'color.': 0.16; 'elsewhere,': 0.16; 'exception?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'highlighted': 0.16; 'idle,': 0.16; 'it;': 0.16; 'level;': 0.16; 'main():': 0.16; 'nesting': 0.16; 'numero': 0.16; 'tab': 0.16; 'tab,': 0.16; 'weird.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'module': 0.19; 'else,': 0.19; 'feb': 0.22; 'input': 0.22; 'otherwise,': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'merge': 0.24; "haven't": 0.24; '(or': 0.24; 'question': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; 'asked': 0.31; 'code': 0.31; 'posting': 0.31; 'usually': 0.31; 'are.': 0.31; 'indentation': 0.31; 'probably': 0.32; 'sense': 0.34; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'much.': 0.36; 'doing': 0.36; "i'll": 0.36; 'should': 0.36; 'wrong': 0.37; 'too': 0.37; 'two': 0.37; 'level': 0.37; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'extremely': 0.39; 'subject:can': 0.39; 'space': 0.40; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'numbers': 0.61; 'simply': 0.61; "you're": 0.61; 'you.': 0.62; "you'll": 0.62; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'close': 0.67; 'eight': 0.74; 'hoping': 0.75; 'honest': 0.78; 'subject:this': 0.83; 'fragment': 0.84; 'min': 0.84; 'tolerate': 0.84; 'to:none': 0.92 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:cc :content-type; bh=XpX9MrphBCmDBDSegMlv6JxXd2K4pVB2xIbTO5pZzhE=; b=F+L6Q/ox+wFE0Mr0AezY6MMzsIlMwZ7aWQvDcbv59qyKiEDORBmBpaBnncx0LIAabg Vv9pX7DZnHgzJkhnz8/wYGbGQc0Up1aX2427Ktex0eQNMAzKwEtkWzAPZFyP9gqphffU SRBQnjs7jQUYMLfW/UeF37vnVBQ3OQ743MqtPk/T9h2PVniznTFBAc6YmMB4Sxri8NVW hz+G9CqMFxLtIGRfm9DWcQDNkaFEoKvYJ9MtjOvoNm/ttSTS3x2TWxVAfGJk17rbBJTQ 0mNYW4oILScHfg0ZbOcpfQWl7kJGEZwKWZCFIfHi9xvmZJkfehwzS+BZWgIo5PqjdfRB cAxg== MIME-Version: 1.0 X-Received: by 10.180.12.115 with SMTP id x19mr4899769wib.19.1392439653412; Fri, 14 Feb 2014 20:47:33 -0800 (PST) In-Reply-To: <045b1b2d-625c-4499-9fa8-d536b1ec4da4@googlegroups.com> References: <045b1b2d-625c-4499-9fa8-d536b1ec4da4@googlegroups.com> Date: Sat, 15 Feb 2014 15:47:33 +1100 Subject: Re: I'm trying to do this code, can somebody help me From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392439654 news.xs4all.nl 2843 [2001:888:2000:d::a6]:49391 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66367 On Sat, Feb 15, 2014 at 3:27 PM, wrote: > 1)Given the variables x , y , and z , each associated with an int , write a fragment of code that assigns the smallest of these to min This is homework. Please be honest about it; we will help you to learn, but we won't write your code for you. > this is what I have > > def main(): > x = eval ( input ("dame el numero X")) > y = eval ( input ("dame el numero Y")) > z = eval ( input ("dame el numero Z")) Using eval is slow and dangerous; what you probably want here is simply int(). > if(x>y and z>y): > min=y > print(min) Oh, you're so close here :) The name "min" should be a clue. If you type this into a Python-sensitive editor like IDLE, it might even be highlighted in a different color. > else: > if(y>x and z>x): > min=x > print(min) > else: > min=z > print(min) > > main() Okay. So why are you posting your code? Is it doing the wrong thing? Is it throwing an exception? Is it sneaking out and kissing your girlfriend? (I will never tolerate a program doing that, especially as it would imply that I have a girlfriend.) Is it working perfectly but you'd like to see it shorter? Are you hoping for a general code review? Ask a question regarding the code. Since you haven't asked anything else, I'll make a few stylistic recommendations. Firstly, indenting by a single space is a bit too compact; it's hard to see exactly how far in you are. I like to use one tab for each indentation level; some prefer to use four spaces, or eight spaces. Two spaces is usually considered too tight; more than eight (or more than one tab) is extremely sparse; three, five, six, and seven are just weird. Four or eight spaces, or exactly one tab, would be the most common. Also, putting your code inside main() and then immediately calling main() doesn't help you much. If you want your module to be importable from elsewhere, you'll need to check __name__, but I suspect you haven't learned that yet. Otherwise, just put all your code at top level and avoid the boiler-plate. Instead of nesting 'if' inside 'else', you can merge the two into a single 'elif', which makes good sense here. What happens if two of your inputted numbers are equal? ChrisA