Question

In: Computer Science

Python.Python.Python. Write a functional program over the automata that accepts odd length binary digits and rejects...

Python.Python.Python. Write a functional program over the automata that accepts odd length binary digits and rejects those that are not. It must include a function called q0 ,q1, accept and reject(). CANNOT USE STRING. OR LENTH.

101 accepted (3 binary digits)

10610 rejected (the number 6 is not a binary number)

101111 rejected (6 digit binary number)

11111 accepted (5 binary digits)

Solutions

Expert Solution

Solution:

Code:

#
# Function to find a odd length binary digits..
#
def isOddLengthBinary(value):
    digit = 0;      #Variable to store single digit
    length = 0;     #Variable to store length

    while (value) :         #Traversing the each digit of value
        digit = value % 10 #Fetching the single digit..  
        length = length + 1     #Counting the length..
        if (digit > 1 or digit < 0):    #Invalid case
            return 0
        else:
            value = value / 10;     #Fetch next digit

    if (length % 2 == 0):
        return 0        #Even length..
    else:
        return 1        #Return success..

def main():
    print("\n\n")
    while(1):
        #Read the value from the user..
        value = input(" Enter any integer value : ")
        if(isOddLengthBinary(int(value))):      #Func call..
            print ("\n Accepted\n") #True case
        else:
            print ("\n Rejected\n") #Fail case    

if __name__ =='__main__':
    main()                  #calling main function..

-----------------------------------------------------

Code screenshot:

-----------------------------------

Sample Output:

-------------------------------------

Kindly upvote if you are satisfied with this solution


Related Solutions

1. Write a Post system that defines the set of binary strings of odd length that...
1. Write a Post system that defines the set of binary strings of odd length that have a “x” as the middle character and "x" is a string
Automata Question. Over the alphabet Σ = {a, b}: 1) Give a DFA, M1, that accepts...
Automata Question. Over the alphabet Σ = {a, b}: 1) Give a DFA, M1, that accepts a Language L1 = { w | w has exactly 2 a’s } 2) Give a DFA, M2, that accepts a Language L2 = { w | w has at least 2 b’s } 3) Give acceptor for L1 intersection L2 4) Give acceptor for L1 - L2
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
1. Enhance Binary System Conversion program with Lab05.2 Addition Function Write a program that accepts two...
1. Enhance Binary System Conversion program with Lab05.2 Addition Function Write a program that accepts two positive binary number in string and perform the addition with Lab05.2 function enhance in a way can accept binary string in addition to decimal string (use input parameter to control the base2 or base10 addition) and output the as binary string. (Optional: Demonstrate 8 bits and 16 bits in length as inputs.) // the example function prototype for addition function below where accepting two...
1. Enhance Binary System Conversion program with Lab05.2 Addition Function Write a program that accepts two...
1. Enhance Binary System Conversion program with Lab05.2 Addition Function Write a program that accepts two positive binary number in string and perform the addition with Lab05.2 function enhance in a way can accept binary string in addition to decimal string (use input parameter to control the base2 or base10 addition) and output the as binary string. (Optional: Demonstrate 8 bits and 16 bits in length as inputs.) // the example function prototype for addition function below where accepting two...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on the command line. For example: prompt$: ./vowcon Operating Systems Class at CSUN The main() in this program should read the phrase from the terminal. This phrase can be read into a global variable. This phrase or its parts can be directly accessed from the main() and from the threads. The main() has to create two threads running functions (vow and con). The main() can...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it constructs a pattern of a diamond of height n If n is even, it constructs an hourglass of length n b) What is the time complexity of the drawShape() function you created? C++ language with for loop
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
A C program that accepts a single command line argument and converts it in to binary...
A C program that accepts a single command line argument and converts it in to binary with array length of 16 bits. The array should contain the binary of the int argument. the program should also convert negative numbers. Side note the command line arg is a valid signed int.
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT