i hate not figuring out on my own but im lost
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?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()
Last edited by Jaan; 10-06-2009 at 03:32 AM. Reason: Please use code tags when you are posting your codes !
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.
wut does the & stand for in python?
and think for the post i will try it in th a.m.
Posted via CodeCall mobi dnt quote me, but it basicly means "and"?
ok thank you
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!"
haha, of course.
oops.
thx![]()
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()
@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()
yes of course. A typing error while moving them around with copy/paste.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks