Homework for Unit 3 Sections 5 and 7
Score of 0.9/1
VOCAB!:
- Boolean Operators: produces booleans after it is used between two values
- Relational Operators: can work between any two values of the same type known as operands, provided that the type supports such types of operators
- Logical Operators: operators that works on operand(s) to produce a single boolean result. Examples include and, or, not.
- Algorithm: A set of instructions that accomplish a task
- Selection: The process that determines which parts of an algoritm is being executed based on a condition that is true or false
- Nested Conditionals: consist of conditional statements within conditional statements
def DecimalToBinary(decimal):
binary = 0
ctr = 0
temp = decimal #copy input decimal
#find binary value using while loop
while(temp > 0):
binary = ((temp%2)*(10**ctr)) + binary
temp = int(temp/2)
ctr += 1
return binary
# Driver Code
num = int(input("Enter a number to convert to binary: "))
print("Binary of " + str(num) + " is:", end=" ")
DecimalToBinary(num)