কম্পিউটার

পাইথন প্রোগ্রাম একটি আইপি অ্যাড্রেস থেকে লিডিং 0 মুছে ফেলতে


IP ঠিকানা নীচে দেওয়া হয়েছে, আমাদের কাজ হল IP ঠিকানা থেকে অগ্রণী শূন্যগুলি সরানো। প্রথমে আমরা প্রদত্ত স্ট্রিংকে "" দ্বারা বিভক্ত করি। এবং তারপরে এটিকে একটি পূর্ণসংখ্যাতে রূপান্তরিত করে এবং অগ্রণী শূন্যগুলিকে সরিয়ে তারপর একটি স্ট্রিংয়ে পুনরায় যুক্ত করুন৷

উদাহরণ

Input : 200.040.009.400
Output : 200.40.9.400

অ্যালগরিদম

Step 1: Input the IP address.
Step 2. Splits the ip by ".".
Step 3: Then convert the string to an integer we can use int (parameter) function.
Step 4: Removes the leading zeroes.
Step 5: Then convert it back to string by str (parameter) and then join them back by using join function.

উদাহরণ কোড

# Python program to remove leading zeros an IP address and print #the IP
# function to remove leading zeros
def IP(ip):
   zeroip = ".".join([str(int(i)) for i in ip.split(".")])
   return zeroip ;
   # Driver code
   ip =input("Enter the IP address ::>")
print("New Ip Address ::>",IP(ip))

আউটপুট

Enter the IP address ::>200.006.020.900
New Ip Address ::> 200.6.20.900

  1. পাইথনের একটি লেবেল থেকে পাঠ্য কীভাবে সরানো যায়?

  2. পাইথন প্রোগ্রাম সেট থেকে আইটেম অপসারণ

  3. পাইথন প্রোগ্রাম একটি তালিকা থেকে ডুপ্লিকেট উপাদান অপসারণ?

  4. একটি প্রদত্ত বাক্য থেকে সমস্ত সদৃশ শব্দ মুছে ফেলার জন্য পাইথন প্রোগ্রাম।