Header Ads

Header ADS

3 Design a Program for creating machines that accept three consecutive ones. Numbers that follow each other continuously in the order from smallest to largest are called consecutive numbers. For example: 1, 2, 3, 4, 5, 6, and so on are consecutive numbers.

 myinput = input("Enter a string of 0 & 1: ")

if len (myinput)<3:

    print("Not Accepted (string length is too small)")


elif len(myinput)==3:

    if myinput=="111":

        print ("Accepted")

    else:

        print ("Not Accepted")


else:

    count1 = 0

    for i in myinput:

        if count1 == 3:

            break

        if i == "1":

            count1 +=1

        else:

            count1 = 0


    if count1 == 3:

        print("Accepted")

    else:

        print("Not Accepted")


No comments

Powered by Blogger.