Unit 3, Sections 5-7
Here are the hacks that we were assigned to do for sections 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('')
number = 3 # value that will affect true or false statement
if number == 5: # if part determines if the statement is true or false compared to another part of the program
print("yes, 5 does equal 5")
else: #else part only executes if the if part is false
print("no, " + str(number) + " does not equal 5")
progress = 0
while progress < 100:
print(str(progress) + "%")
if progress == 50:
print("Half way there")
progress = progress + 10
print("100%" + " Complete")
Age = int(input("How old are you?"));
print(Age)
if (Age >= 18):
print("You are old enough to vote!")
if(Age >= 65):
print("You are a senior citizen!")
else:
print("You are too young to vote!")
def DecimalToBinary(num):
strs = ""
while num:
# if (num & 1) = 1
if (num & 1):
strs += "1"
# if (num & 1) = 0
else:
strs += "0"
# right shift by 1
num >>= 1
return strs
# function to reverse the string
def reverse(strs):
return strs[::-1]
# user inputs the number they would like to convert to binary
user_input = int(input("What number would you like to convert to binary?"))
print(f'{user_input} was chosen')
print(f'{user_input} converted to binary is {reverse(DecimalToBinary(user_input))}')
def function(x, y, z):
if(x > y):
print("x is greater than y")
if(x > z):
print("x is greater than y and z")
else:
print("x is only greater than y")
else:
print("x is less than y and z")
function(2, 3, 5)