3.5-7
print("True:",4 == 4)
print("True:",1 > 0)
print("False:",7 <= 3)
print("True:",5 != 6)
print("False:",7 == 8)
print("True:",3 == 3)
print('')
# Same as above, but now for other values other than int
print('True:',"as" =="as")
print("False:",True == False)
print("False:",[2,3,1] < [2,3,1])
print("True:",'af' <='bc')
print("False:",'ce' > 'cf')
print("True:",[1,'b'] > [1,'a'])
print('')
print("True:", True or False)
print("False:", not True)
print("True:", True and True)
print("False:", not True)
print("False:", True and False)
print("True:", not False)
Age = 30;
if (Age == 30):
print("your old")
else:
print("you should retire");
if (Age > 50):
print("You have a beard");
number = int(input("What number would you like to convert? Please enter an Integer"))
pow = 0
while 2**pow <= number:
pow += 1
answer = ""
for i in range(pow-1,-1,-1):
if number >= 2**i:
answer += "1"
number -= 2**i
else:
answer += "0"
print("The binary form of the decimal number " + str(number) + " is " + answer)
bintooct = {"000":"0","001":"1","010":"2","011":"3","100":"4","101":"5","110":"6","111":"7"}
while len(answer)%3 != 0:
answer = "0"+answer
oct = ""
for i in range(0,len(answer)-2,3):
oct += bintooct[answer[i:i+3]]
print("The octal form of the decimal number " + str(number) + " is " + oct)
Notes:
- A boolean is an expression that can be true or false
- Boolean operators include:
- Not: !,changes true to false and false to true
- And: and, returns true if two boolean expressions are true
- Or: or, returns true if one of two boolean expressions are true
- Xor: returns true if two boolean expressions are different(both trye or both false)
- <,>, >=, <= : Mathematical operators which return true if a number or string(alphabetically) is that operator relative to the other one
- Comparison operators can be used with arrays two, looking at the first index, then the second, and so on