কম্পিউটার

একটি বাইনারি সংখ্যায় K ধারাবাহিক 1 আছে কিনা তা পরীক্ষা করার জন্য পাইথন প্রোগ্রাম?


প্রথমে আমরা 1's এবং 0's এর সংমিশ্রণে একটি ব্যবহারকারীর ইনপুট স্ট্রিং নিই। তারপর 1's দিয়ে একটি নতুন স্ট্রিং তৈরি করি, তারপর পরপর 1 এর কোনো p সংখ্যা আছে কি না তা পরীক্ষা করে দেখুন। যদি উপস্থিত থাকে তাহলে FOUND দেখান অন্যথায় NOTFOUND.

উদাহরণ

Binary number ::1111001111
Enter consecutive 1’s :3
Consecutive 1's is Found

অ্যালগরিদম

Step 1: input a string with the combination of 1’s, it’s stored in the variable X and 0’s and p is the consecutive 1’s in a binary number.
Step 2: form a new string of p 1’s.
   newstring=”1”*p
Step 3: check if there is p 1’s at any position.
   If newstring in X
      Display “FOUND”
   Else
      Display “NOT FOUND”
   End if

উদাহরণ কোড

# To check if there is k consecutive 1's in a binary number 
def binaryno_ones(n,p):
   # form a new string of k 1's 
   newstr = "1"*p

   # if there is k 1's at any position 
   if newstr in n:
      print ("Consecutive 1's is Found")
   else:
      print (" Consecutive 1's is Not Found")

# driver code
n =input("Enter Binary number ::")
p = int(input("Enter consecutive 1's ::"))
binaryno_ones(n, p)

আউটপুট

Enter Binary number ::1111001111
Enter consecutive 1's ::3
Consecutive 1's is Found

  1. পাইথন প্রোগ্রামে দশমিককে বাইনারি নম্বরে রূপান্তর করুন

  2. প্রাইম নম্বর চেক করতে পাইথন প্রোগ্রাম

  3. পাইথন প্রোগ্রাম পরপর 1’ ছাড়া বাইনারি স্ট্রিং সংখ্যা গণনা করতে

  4. আর্মস্ট্রং নম্বর চেক করতে পাইথন প্রোগ্রাম