Skip to main content

Posts

Showing posts with the label python

use of /r to clear your terminal

Self-Destructing Terminal Messages in Python Published on December 18, 2025 by AI Developer Ever wanted to create a dramatic "self-destructing" message in your terminal, like something straight out of a spy movie? This clever Python trick uses terminal cursor control and timing to make text appear to vanish before your eyes! How It Works The magic happens through ANSI escape sequences and timing control: Cursor positioning: \r returns the cursor to the start of the line Overwriting: 50 spaces completely cover the original message Timing: time.sleep(3) creates the suspenseful pause Flush output: Ensures immediate display without buffering Try This Code Yourself import time import sys print("This message will self-destruct in 3 seconds...", end="", flush=True) time.sleep(3) # \r moves cursor to start # " " * 50 writes 50 spaces to overwrite the t...

Roman Number to Integer

This website describe common assumption and failure during gfg coding. python Failed class Solution: def romanToDecimal(self, s): # code here val={ '':1, 'X':10, 'L':50, 'M':1000, 'C':100, 'V':5 } sum=0 s=s[::-1] count=0 for i in s: if count==1: count=0 sum-=val[i] else: sum+=val[i] count+=1 return sum Reason Your current implementation of `romanToDecimal()` has the right spirit, but the logic for subtractive notation (like `IV`, `IX`, `XL`, etc.) is off. You're using a `count` flag, which doesn't reliably detect when subtraction should occur. --- ⚠️ Issues: 1. Incorrect subtraction logic : Roman numerals subtract only when a smaller value precedes a larger...

Balancing brackets

we are going to make the logic for isbalanced function correct.This article is part of my efforts where i have made many mistakes while thinking about problem solution which iam just recording over here.Finally i will also have the correct anwser in the same language.As it is self explanatory no Explantion. Test Case 1 Python Failure class Solution: def isequal(self,f,s): ok=[['(',')'], ['[',']'], ['{','}'], ] for i in ok: s=s.replace(i[1],i[0]) if f==s: return True else : return False def isBalanced(self, s): # code here s=s.strip() s.replace(" ","") n=len(s) #should be even if n%2!=0: return False m=n//2 f=s[:m] t=s[m:] t=t[::-1] return self.isequal(f,t) My above program got fa...

find the sum of 3 numbers to find next term

This Blog post Describe How to your may find this algorithm else where too. In this Problem Algorithm: We are given a three digits of sequence after that,we need to find the next element in the array,for Example :- [0,2,4] By suming the previous Three Elements,means [0+2+4]=next_term Hence the next term in the array is 6.Now the array is [0,2,4,6]. Intution: Here are the few conditions return mod value of the following sequence. Every time return the sum of last three numbers. def find_nth_term (n) : mod = 10 ** 9 + 7 if n<= 3 : return sequence[n- 1 ] for i in range( 4 ,n+ 1 ): next_term=sequence[- 1 ]+sequence[- 2 ]+sequence[- 3 ]%mod sequence.append(next_term) return sequence[- 1 ] n=int(input()) #Ouput the nth term modulo (10**9+7) result=find_nth_term(n) print(result)

How To Change The Owner Of A Directory Using Python?

Introduction: To change the permission of a directory or file in python you needed to know two thing your user name and user group you wanted to change I will going to describe in detail how to know your users on your computer and user group present on your computer, whether you are the window or linux or mac. Syntax : There are three main commands we can use are 1st command(main command) os.chown(directory_name,userid,groupid) Parameters: userid - user id is the parameter used to specify the user id. groupid - Is the group id used for specifying the group of the group id. 2nd command: usr.getpwnam(new_owner_user).pw_uid Above function returns user id. when username is passed as argument. 3rd Command: grp.getgrnam(new_owner_group).gr_gid Above function returns group id. when groupname is passed as argument. Sample Program : Python3 import os # Directory path you want to change ownership for directory_path = '/tmp/directory' # New owner user and group new_owner_user = 'ch...

Enhancing Automation with Python: My Personal Helper Bot for PC

Incorporating this project into one of my automation endeavors has proved highly advantageous. The benefits are numerous, significantly improving my efficiency and experience: Advantages: Swift Program Launching: The program launches applications swiftly, far quicker than traditional manual methods. Efficient Data Retrieval: The search time for specific data has drastically reduced. It opens a new browser tab swiftly and presents my search results using Google’s search engine. Speedy File Access: Program files open much faster, catering precisely to my needs. Speed is of the essence, and this feature delivers! Automated Screenshots: The program effortlessly captures screenshots on my command, saving them in JPG format. A simple click on a button achieves this task. Disadvantage: Command-Based Interaction: The system operates solely on command input and does not support verbal instructions. Limited File Search Capability: The program cannot conduct searches f...