def reverse_string(s):
return s[::-1]
input_string = input("Enter a string: ")
reversed_string = reverse_string(input_string)
print("Reversed string:", reversed_string)
#source code --> clcoding.com
Python Developer December 31, 2024 Python Coding Challenge No comments
def reverse_string(s):
return s[::-1]
input_string = input("Enter a string: ")
reversed_string = reverse_string(input_string)
print("Reversed string:", reversed_string)
#source code --> clcoding.com
Python Developer December 31, 2024 Python Coding Challenge No comments
Lambda Function Definition:
remainder is defined as a lambda function that takes two arguments, a and b.
The function calculates the remainder when a is divided by b using the modulo operator %.
The syntax for the modulo operation is:
a % b
This operation returns the remainder of the division of a by b.
Calling the Function:
The function remainder is called with a = 10 and b = 3.
Modulo Operation:
Inside the lambda function, the expression 10 % 3 is evaluated.
10 % 3 means "divide 10 by 3 and find the remainder."
When 10 is divided by 3, the quotient is 3 (since 3 * 3 = 9), and the remainder is 10 - 9 = 1.
Result Assignment:
The calculated remainder (1) is assigned to the variable result.
Printing the Result:
The print(result) statement outputs the value stored in result, which is 1.
Output
1
Python Developer December 31, 2024 Python Coding Challenge No comments
Lambda Function Definition:
The function greater is defined using a lambda function.
The lambda function takes two arguments, a and b.
It uses a conditional expression (also called a ternary operator) to compare a and b. The structure is:
a if a > b else b
If a > b is True, the function returns a.
If a > b is False, the function returns b.
Calling the Function:
The function greater(8, 12) is called with a = 8 and b = 12.
Condition Evaluation:
Inside the lambda function, the condition a > b is evaluated, i.e., 8 > 12.
This condition is False because 8 is not greater than 12.
Returning the Result:
Since the condition a > b is False, the function returns b, which is 12.
Printing the Result:
The result 12 is stored in the variable result.
The print(result) statement outputs 12.
Output
12
Python Developer December 31, 2024 Python Coding Challenge No comments
Python Developer December 31, 2024 Python Coding Challenge No comments
Python Coding December 30, 2024 Python Quiz No comments
Assign x = 5:
Assign y = (z := x ** 2) + 10:
After this line:
Print Statement:
Output: The program prints:
x=5 y=35 z=25
Walrus Operator (:=):
Order of Operations:
Unrelated Variables:
If we didn’t use the walrus operator, the code could be written as:
x = 5z = x ** 2
y = z + 10print(f"{x=} {y=} {z=}")
This would produce the same output:
x=5 y=35 z=25
Using the walrus operator is helpful for:
Python Developer December 29, 2024 100 Python Programs for Beginner No comments
def replace_a_with_dollar(input_string):
result = input_string.replace('a', '$')
return result
input_string = input("Enter a string: ")
output_string = replace_a_with_dollar(input_string)
print("Modified string:", output_string)
#source code --> clcoding.com
Python Coding December 29, 2024 Python No comments
import matplotlib.pyplot as plt
years = [2014, 2016, 2018, 2020, 2022, 2024]
languages = ["Python", "JavaScript", "TypeScript", "Java", "C#"]
rankings = [
[8, 6, 5, 3, 2, 1], [1, 2, 2, 2, 3, 2],
[10, 9, 8, 5, 5, 3], [2, 3, 3, 4, 4, 4],
[5, 4, 4, 6, 6, 5], ]
colors = ["lime", "magenta", "purple", "orange", "cyan", ]
plt.figure(figsize=(10, 6))
for i, (language, ranking) in enumerate(zip(languages, rankings)):
plt.plot(years, ranking, label=language, color=colors[i], linewidth=2)
plt.gca().invert_yaxis()
plt.xticks(years, fontsize=10)
plt.yticks(range(1, 13), fontsize=10)
plt.title("Programming Language Trends (2014 - 2024)", fontsize=14)
plt.xlabel("Year", fontsize=12)
plt.ylabel("Rank", fontsize=12)
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fontsize=9)
plt.grid(color='gray', linestyle='--', linewidth=0.5, alpha=0.7)
plt.tight_layout()
plt.show()
def remove_nth_index_char(input_string, n):
"""
Remove the character at the nth index from the input string.
Args:
input_string (str): The string to process.
n (int): The index of the character to remove.
Returns:
str: A new string with the nth character removed.
"""
if n < 0 or n >= len(input_string):
raise ValueError("Index n is out of range.")
return input_string[:n] + input_string[n+1:]
if __name__ == "__main__":
input_string = input("Enter a non-empty string: ")
try:
n = int(input("Enter the index of the character to remove: "))
result = remove_nth_index_char(input_string, n)
print("String after removing the nth index character:", result)
except ValueError as e:
print("Error:", e)
#source code --> clcoding.com
Python Coding December 29, 2024 Python Quiz No comments
List Initialization:
Using the .sort() Method:
So, when you assign the result of my_list.sort() back to my_list, you are overwriting the original list with None.
Printing the Result:
Python Coding December 29, 2024 Python No comments
Python Adoption Records:
Most Downloaded Libraries:
Longest Python Code Base:
Most Forked GitHub Python Repository:
Highest Salary for Python Developers:
Top Trending Python Tools in 2024:
Learning Python in 2024:
Popularity and Adoption:
New Features in Python 3.13:
AI and Machine Learning:
PyCaret 3.0
and LangChain
gained traction for low-code AI and generative AI applications.Web Development:
Community and Events:
Lambda Function:
lambda a, b: abs(a - b) defines an anonymous function (lambda function) that takes two arguments, a and b.
The function calculates the absolute difference between a and b using the abs() function.
abs(x) returns the absolute value of x (i.e., it removes any negative sign from the result).
Assigning the Function:
absolute_diff = lambda a, b: abs(a - b) assigns the lambda function to the variable absolute_diff.
Now, absolute_diff can be used as a regular function to compute the absolute difference between two numbers.
Calling the Function:
result = absolute_diff(7, 12) calls the absolute_diff function with the arguments 7 and 12.
Inside the function:
a−b=7−12=−5.
abs(-5) evaluates to 5, as the abs() function removes the negative sign.
Printing the Result:
print(result) outputs the value of result to the console, which is 5.
Output:
The program prints:
5
Python Developer December 28, 2024 Python Coding Challenge No comments
Lambda Function:
lambda x: x ** 0.5 defines an anonymous function (lambda function) that takes a single argument x.
The body of the function is x ** 0.5, which calculates the square root of x.
In Python, raising a number to the power of 0.5 is equivalent to taking its square root.
Assigning the Function:
sqrt = lambda x: x ** 0.5 assigns the lambda function to the variable sqrt.
Now, sqrt can be used as a regular function to compute square roots.
Calling the Function:
result = sqrt(16) calls the sqrt function with the argument 16.
Inside the function:
16 ** 0.5 is calculated.
The function returns 4.0.
Printing the Result:
print(result) outputs the value of result to the console, which is 4.0.
Output:
The program prints:
4.0
Note:
The result is 4.0 (a float), even though the square root of 16 is 4, because the ** operator with 0.5 produces a floating-point number.
If you want the output as an integer, you can cast the result to an int:
sqrt = lambda x: int(x ** 0.5)
result = sqrt(16)
print(result)
This would print:
4
Python Developer December 28, 2024 Python Coding Challenge No comments
Python Developer December 28, 2024 Python Coding Challenge No comments
Python Developer December 28, 2024 100 Python Programs for Beginner No comments
"""
Remove characters at odd indices from the input string.
Args:
input_string (str): The string to process.
Returns:
str: A new string with characters at odd indices removed.
"""
return input_string[::2]
if __name__ == "__main__":
input_string = input("Enter a string: ")
result = remove_odd_indexed_chars(input_string)
print("String after removing odd indexed characters:", result)
#source code --> clcoding.com
Python Developer December 28, 2024 100 Python Programs for Beginner No comments
import string
def is_pangram(sentence):
"""
Check if a sentence is a pangram.
A pangram contains every letter of the English alphabet at least once.
Args:
sentence (str): The input string to check.
Returns:
bool: True if the sentence is a pangram, False otherwise.
"""
alphabet = set(string.ascii_lowercase)
letters_in_sentence = set(char.lower() for char in sentence if char.isalpha())
return alphabet <= letters_in_sentence
if __name__ == "__main__":
input_sentence = input("Enter a sentence: ")
if is_pangram(input_sentence):
print("The sentence is a pangram.")
else:
print("The sentence is not a pangram.")
#source code --> clcoding.com
Python Coding December 28, 2024 Python Tips No comments
This code uses list comprehension, a concise way to create lists in Python. The general structure is:
[expression for item in iterable if condition]
The numbers are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Keep only even numbers:
0, 2, 4, 6, 8
Calculate the square of each even number:
The resulting list is:
[0, 4, 16, 36, 64]
The code prints:
[0, 4, 16, 36, 64]
Python Developer December 27, 2024 Python Coding Challenge No comments
List Creation:
a is assigned a list containing one element: [10].
b is assigned a separate list containing the same element: [10].
Identity Comparison (is):
The is operator checks whether two variables refer to the same object in memory (i.e., have the same identity).
Although a and b have the same content ([10]), they are stored in different locations in memory. They are two distinct objects.
Result:
Since a and b are distinct objects, a is b evaluates to False.
Important Note:
If you want to check if the contents of a and b are the same, you should use the equality operator (==):
print(a == b) # This will return True because the content of both lists is identical.
Output:
False
Python Developer December 27, 2024 Python Coding Challenge No comments
Initialization:
my_list is initialized as a list containing three elements: [1, 2, 3].
Using append:
The append method adds a single element to the end of a list.
Here, [4, 5] is a list, and it's treated as a single element.
After the append operation, my_list becomes [1, 2, 3, [4, 5]].
Notice that [4, 5] is now a sublist (nested list) within my_list.
Using len:
The len function returns the number of top-level elements in the list.
In my_list = [1, 2, 3, [4, 5]], there are four top-level elements:
1
2
3
[4, 5] (the entire sublist is considered one element).
Output:
The length of my_list is 4.
Final Output:
4
Python Developer December 27, 2024 Python Coding Challenge No comments
Initialize the List:
cl is initialized as an empty list [].
Multiply the List:
When you multiply a list by an integer, Python creates a new list where the elements of the original list are repeated.
Syntax: list * n → repeats the elements of list, n times.
Empty List Multiplied:
Since cl is an empty list, repeating its elements (even 2 times) results in another empty list because there are no elements to repeat.
Output:
The result of cl * 2 is [].
[]
Python Developer December 27, 2024 100 Python Programs for Beginner No comments
from gtts import gTTS
import os
def create_audiobook(text_file, output_file):
with open(text_file, 'r', encoding='utf-8') as file:
text = file.read()
tts = gTTS(text=text, lang='en')
tts.save(output_file)
print(f"Audiobook saved as {output_file}")
text_file = "clcoding_hindi.txt"
output_file = "clcoding_hindi.mp3"
create_audiobook(text_file, output_file)
os.system(f"start {output_file}")
#source code --> clcoding.com
Python Developer December 27, 2024 100 Python Programs for Beginner No comments
def gcd(a, b):
"""
Function to calculate GCD of two numbers using recursion
"""
if b == 0:
return a
else:
return gcd(b, a % b)
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = gcd(num1, num2)
print(f"The GCD of {num1} and {num2} is {result}")
#source code --> clcoding.com
Python Coding December 27, 2024 Python Quiz No comments
The sum() function adds all the elements of the list:
sum([0, 6, 0, 8]) = 14
The code outputs : 14
Python Coding December 27, 2024 Python No comments
import random
from pyfiglet import Figlet
from termcolor import colored
TEXT = "Happy New Year 2025"
COLOR_LIST = ['red', 'green', 'blue', 'yellow']
with open('texts.txt') as f:
font_list = [line.strip() for line in f]
figlet = Figlet()
for _ in range(1):
random_font = random.choice(font_list)
random_color = random.choice(COLOR_LIST)
figlet.setFont(font=random_font)
text_art = colored(figlet.renderText(TEXT), random_color)
print("\n", text_art)
#source code --> clcoding.com
Python Coding December 26, 2024 Python No comments
pip install SpeechRecognition pydub
import speech_recognition as sr
recognizer = sr.Recognizer()
audio_file = "audiobook.wav"
from pydub import AudioSegment
AudioSegment.from_mp3(audio_file).export(audio_file , format="wav")
with sr.AudioFile(audio_file) as source:
audio_data = recognizer.record(source)
try:
text = recognizer.recognize_google(audio_data)
print("Extracted Text:", text)
except sr.UnknownValueError:
print("Could not understand the audio.")
except sr.RequestError as e:
print("API Error:", e)
Python Developer December 26, 2024 100 Python Programs for Beginner No comments
def find_lcm(a, b):
def find_gcd(a, b):
if b == 0:
return a
else:
return find_gcd(b, a % b)
return abs(a * b) // find_gcd(a, b)
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
lcm = find_lcm(num1, num2)
print(f"The LCM of {num1} and {num2} is {lcm}.")
#source code --> clcoding.com
Python Developer December 26, 2024 100 Python Programs for Beginner No comments
def find_gcd(a, b):
while b:
a, b = b, a % b
return a
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
gcd = find_gcd(num1, num2)
print(f"The GCD of {num1} and {num2} is {gcd}.")
#source code --> clcoding.com
Python Coding December 26, 2024 Python Quiz No comments
data = [1, 2, 3]
This creates a list named data
with three elements: 1,2,3.
output = {*data, *data}
Here:
Result:
output = {1, 2, 3}
print(output)
The print statement outputs the set output:
{1, 2, 3}
{1, 2, 3}
Free Books Python Programming for Beginnershttps://t.co/uzyTwE2B9O
— Python Coding (@clcoding) September 11, 2023
Top 10 Python Data Science book
— Python Coding (@clcoding) July 9, 2023
🧵:
Top 4 free Mathematics course for Data Science ! pic.twitter.com/s5qYPLm2lY
— Python Coding (@clcoding) April 26, 2024
Web Development using Python
— Python Coding (@clcoding) December 2, 2023
🧵: