Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: if greater than but less than

  1. #1
    opencircles is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    if greater than but less than

    i hate not figuring out on my own but im lost
    Code:
    a = input("please enter your age: ")
    
    if a >= 18:
        print"you may enter"
    else:
        print"you are to young."
    if a > 110:
        print "invalid age entered"
    
    
    raw_input()
    obviously if anythin over 110 is input then it says ivalid age entered but also says you may enter. how do i write if a >= 18 but < 110?
    Last edited by Jaan; 10-06-2009 at 03:32 AM. Reason: Please use code tags when you are posting your codes !

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Hot_Milo23's Avatar
    Hot_Milo23 is offline Programmer
    Join Date
    Jun 2009
    Location
    Western Australia
    Posts
    120
    Rep Power
    11

    Re: if greater than but less than

    Posted via CodeCall Mobile
    i cant check this atm, but off the top of my head, you could try:
    if a>18 && a<110....
    or it could be only one &.
    hope that helps.

  4. #3
    opencircles is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0
    wut does the & stand for in python?

    and think for the post i will try it in th a.m.

  5. #4
    Hot_Milo23's Avatar
    Hot_Milo23 is offline Programmer
    Join Date
    Jun 2009
    Location
    Western Australia
    Posts
    120
    Rep Power
    11

    Re: if greater than but less than

    Posted via CodeCall mobi dnt quote me, but it basicly means "and"?

  6. #5
    opencircles is offline Newbie
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Re: if greater than but less than

    ok thank you

  7. #6
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31

    Re: if greater than but less than

    You're getting confused with C. In C, && is a logical and, whereas a single & is a bitwise and.

    In python, its just 'and', so:

    Code:
    if (a >= 18) and (a <= 110):
       print "Zomg!"

  8. #7
    Hot_Milo23's Avatar
    Hot_Milo23 is offline Programmer
    Join Date
    Jun 2009
    Location
    Western Australia
    Posts
    120
    Rep Power
    11

    Re: if greater than but less than

    haha, of course.
    oops.
    thx

  9. #8
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: if greater than but less than

    You should do it like this instead(using an elif block):

    Code:
     
    a = input("please enter your age: ")
     
    if a > 110:
        print "invalid age entered"
    elif a >= 18:
        print "you may enter"enter"
    else:
        print "you are to young."
     
     
     
    raw_input()

  10. #9
    UnknownFear's Avatar
    UnknownFear is offline Learning Programmer
    Join Date
    Oct 2009
    Location
    Toronto, Ontario
    Posts
    47
    Blog Entries
    1
    Rep Power
    0

    Re: if greater than but less than

    @Vswe: But take out the extra "enter"

    Code:
    a = input("please enter your age: ")
     
    if a > 110:
        print "invalid age entered"
    elif a >= 18:
        print "you may enter"
    else:
        print "you are to young."
    
    raw_input()

  11. #10
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: if greater than but less than

    yes of course. A typing error while moving them around with copy/paste.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 12-16-2009, 11:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts