100 Networking Questions
Basic Python Programming Write a Python program to reverse a string. (I have also added code for reverse a list) #Reverse a string a="Hello" try: print(a[::-1]) #Reverse a list b=[1,'a',"Suchi"] print(b[::-1]) print(b[2]) c=b[2] print(c[::-1]) except Exception as e: print("Error Found"+e) Reasoning: [::-1] is Python slicing syntax: : refers to the entire sequence. -1 specifies the step (reverse direction). This avoids using loops, making the program concise and efficient. 2. Implement a function to check if a number is prime. num=23 if num<2: print("Not Prime") for i in range(2,int(num**0.5)+1): if num%i==0: print("Not Prime") print(num," is Prime ") Reasoning: A prime number is only divisible by 1 and itself. Checking divisors up to the square root of n reduces time complexity...