def integer_0_or_1(interger):     #if value is true return 1     if truth_value:         return 1     else:         #else return 0         return 0 def truth_value(integer):     """Convert an integer into a truth value."""     # Convert 0 into False and all other integers,     # including 1, into True     if integer == 0:         truth_value = False     else:         truth_value = True     return truth_value      print(truth_value(True)) print(truth_value(False)) This question assesses Block 2 Part 4. It assumes an understanding of binary notation and truth tables (Block 1 Part 1).   Write a function and_binary(), which takes two integers (each is either 0 or 1) and returns an integer in accordance with the truth table: A B and_binary(A, B) 0 0 0 0 1 0 1 0 0 1 1 1   Before you dive into writing your function, first decompose the problem. Then, write an algorithm. Only after that, implement your solution in Python.    Hint: When you have decomposed the problem, you should be able to implement some of the sub-problems by using:    the function truth_value() from the previous quiz question the function integer_0_or_1() from the previous quiz question  Python’s and Boolean operator.     Recall that the Boolean operators and, or and not can be used to carry out Boolean operations on the truth values. This is illustrated by the following calls in the Python shell: >>> not(True) False >>> True and not(False) True You can apply the operators to the literals True and False, as shown above, and also to variables that have been assigned to the value True or the value False: >>> truth_value_1 = True >>> truth_value_2 = False >>> truth_value_1 and truth_value_2 False You will find  the definitions of truth_value() and integer_0_or_1() in the answer box below. All you need to add below is your definition of the function and_binary(). It will be tested automatically against relevant inputs (i.e. the test cases that are represented by the truth table for and_binary() that is provided above). So, add your function definition and nothing more.         For example: Test Result print(and_binary(0, 0)) 0 the first code is mine but it won't pass the inbuilt tests of my quiz

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

def integer_0_or_1(interger):
    #if value is true return 1
    if truth_value:
        return 1
    else:
        #else return 0
        return 0
def truth_value(integer):
    """Convert an integer into a truth value."""
    # Convert 0 into False and all other integers,
    # including 1, into True
    if integer == 0:
        truth_value = False
    else:
        truth_value = True
    return truth_value

    

print(truth_value(True))
print(truth_value(False))

This question assesses Block 2 Part 4. It assumes an understanding of binary notation and truth tables (Block 1 Part 1).

 

Write a function and_binary(), which takes two integers (each is either 0 or 1) and returns an integer in accordance with the truth table:

A

B

and_binary(A, B)

0

0

0

0

1

0

1

0

0

1

1

1

 

Before you dive into writing your function, first decompose the problem. Then, write an algorithm. Only after that, implement your solution in Python. 

 

Hint: When you have decomposed the problem, you should be able to implement some of the sub-problems by using: 

 

  • the function truth_value() from the previous quiz question
  • the function integer_0_or_1() from the previous quiz question 
  • Python’s and Boolean operator.
 
 

Recall that the Boolean operators and, or and not can be used to carry out Boolean operations on the truth values. This is illustrated by the following calls in the Python shell:

>>> not(True)
False
>>> True and not(False)
True

You can apply the operators to the literals True and False, as shown above, and also to variables that have been assigned to the value True or the value False:

>>> truth_value_1 = True
>>> truth_value_2 = False
>>> truth_value_1 and truth_value_2
False

You will find  the definitions of truth_value() and integer_0_or_1() in the answer box below. All you need to add below is your definition of the function and_binary(). It will be tested automatically against relevant inputs (i.e. the test cases that are represented by the truth table for and_binary() that is provided above). So, add your function definition and nothing more.

 

 

 

 

For example:

Test Result
print(and_binary(0, 0))
0

the first code is mine but it won't pass the inbuilt tests of my quiz

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

this is the error i am getting on test

Test
Expected Got
Xprint(and_binary(0, 0)) 0
print (and_binary (0, 1)) 0
print(and_binary(1,
0)) 0
print(and_binary(1,
1)) 1
0
0
0
True
False
0
0
0
1
X
Transcribed Image Text:Test Expected Got Xprint(and_binary(0, 0)) 0 print (and_binary (0, 1)) 0 print(and_binary(1, 0)) 0 print(and_binary(1, 1)) 1 0 0 0 True False 0 0 0 1 X
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT