Skip to main content

Posts

Basic python programs पाइथन के बेसिक प्रोग्राम

1.) Python program to print message "Hello, World!". print("Hello, World!") 2.) Python program to check if a Number is Even or Odd. num = int(input("Enter a number: ")) if num % 2 == 0:     print(f"{num} is an even number.") else:     print(f"{num} is an odd number.") 3.) Python program to find the Sum of Two Numbers. num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) sum = num1 + num2 print(f"The sum of {num1} and {num2} is {sum}.") 4.) Python program to calculate Factorial of a Number. num = int(input("Enter a Positive Integer Number: ")) factorial = 1 if num < 0:     print("Factorial does not exist for negative numbers.") elif num == 0:     print("The factorial of 0 is 1.") else:     for i in range(1, num + 1):         factorial *= i     print(f"The factorial of {num} is {factorial}.") 5.) Python program for Simp...

in and not in keywords of Python पाइथन में इन एवं नॉट इन कीवर्ड

In Python, the keywords `in` and `not in` are used to check membership in sequences or collections, such as lists, tuples, strings, sets, or dictionaries. These keywords allow you to determine whether a specific value exists within a collection or not. पायथन में, कीवर्ड 'इन' और 'नॉट इन' का उपयोग अनुक्रमों या संग्रहों, जैसे सूचियों, टपल्स, स्ट्रिंग्स, सेट या शब्दकोशों में सदस्यता की जांच करने के लिए किया जाता है। ये कीवर्ड आपको यह निर्धारित करने की अनुमति देते हैं कि किसी संग्रह में कोई विशिष्ट मान उपस्थित है या नहीं। 1)`in` Keyword:- The `in` keyword is used to check if a value exists within a sequence or collection. `इन` कीवर्ड का उपयोग यह जांचने के लिए किया जाता है कि किसी अनुक्रम या संग्रह में कोई मान उपस्थित है या नहीं। If the `value` exists in the given `collection`, this expression returns `True`; otherwise, it returns `False`. यदि दिए गए `संग्रह` में `मान` उपस्थित है, तब यह अभिव्यक्ति `सही` लौटाती है; अन्यथा, यह 'गलत' लौटाता है। Syntax:- value in collecti...

break, continue, and pass in Python पायथन में, `ब्रेक`, ` कंटिन्यू`, और `पास`

In Python, `break`, `continue`, and `pass` are control flow statements used in for and while loops and conditional if-else. पायथन में, `ब्रेक`, ` कंटिन्यू`, और `पास` नियंत्रण प्रवाह के कथन हैं जिनका उपयोग फॉर और व्हाइल लूप और कंडीशनल इफ-एल्स में किया जाता है। 1.) break statement:- It Exits the loop immediately, regardless of the iteration count or condition. It is commonly used to stop a loop when a certain condition is met. 1.) ब्रेक स्टेटमेंट:- यह पुनरावृत्ति गणना या स्थिति की परवाह किए बिना तुरंत लूप को समाप्त कर देता है। इसका उपयोग आमतौर पर एक निश्चित शर्त पूरी होने पर लूप को रोकने के लिए किया जाता है। Syntax:-  break Example:- for i in range(5):   if i == 3:      break   print(i) Output:- 0 1 2 2.) continue statement:- It skips the rest of the code inside the loop for the current iteration and moves to the next iteration. It is Useful when we want to skip certain conditions in the loop but continue iterating. 2.) कंटिन्यू कथन: - यह वर्तमान पुनरावृत्ति ...

loop structure in python for loop and while loop पायथन में लूप संरचना फॉर लूप और व्हाइल लूप

A loop structure or iterative structure or repetitive structure in programming refers to a control flow mechanism that allows a set of instructions or code to be executed repeatedly based on a condition or over a collection of items. Loops help automate repetitive tasks and reduce redundancy in code. प्रोग्रामिंग में एक लूप संरचना या पुनरावृत्त संरचना या दोहराव संरचना एक नियंत्रण प्रवाह तंत्र को संदर्भित करती है जो किसी शर्त के आधार पर या वस्तुओं के संग्रह पर निर्देशों या कोड के एक सेट को बार-बार निष्पादित करने की अनुमति देती है। लूप्स दोहराए जाने वाले कार्यों को स्वचालित करने और कोड में अतिरेक को कम करने में मदद करते हैं। Key Components of a Loop Structure:- लूप संरचना के प्रमुख घटक:- A.) Initialization:- The starting point or value for the loop. ए.) इनिशियलाइज़ेशन:- लूप के लिए शुरुआती बिंदु या मान। B.) Condition:- The logical test that determines whether the loop should continue or stop. बी) स्थिति:- तार्किक परीक्षण जो यह निर्धारित करता है कि लूप जारी रहना चाहिए या बंद हो जाना चाहिए।...

Conditional statements in Python if, if-else, if-elif-else पायथन में सशर्त कथन

  In Python, conditional statements help you make decisions in the code. There are three main types of conditionals:- पायथन में, सशर्त कथन आपको कोड में निर्णय लेने में मदद करते हैं। सशर्त के तीन मुख्य प्रकार हैं:-  1.) Conditional `if` statement:- An `if` statement executes the code block only if the condition evaluates to `True`. 1.) सशर्त `if` कथन:- एक `if` स्टेटमेंट कोड ब्लॉक को केवल तभी निष्पादित करता है जब स्थिति सही पर मूल्यांकन करती है। Syntax:- if condition:    Statement(s) Example:- x = 10 if x > 5:     print("x is greater than 5") 2.) Alternative `if-else` statement:  An `if-else` statement checks a condition and executes a block of code('if' block), if the condition is true otherwise provides an alternative block of code ('else' block), if the condition is false. 2.) वैकल्पिक `if- else` कथन:- एक `if-else` स्टेटमेंट एक शर्त की जाँच करता है और कोड के एक ब्लॉक ('if' ब्लॉक) को निष्पादित करता है, यदि स्थिति सही है अन्यथा कोड का एक वैकल्पिक ब्ल...

Input and Output statements in Python

In Python, input and output are handled using built-in functions input() and print(). पायथन में, इनपुट और आउटपुट को अंतर्निहित फ़ंक्शन इनपुट() और प्रिंट() का उपयोग करके नियंत्रित किया जाता है। 1.) input():- To take input from the user, we can use the `input()` function. This function reads a line usually from a standard input device (keyboard) and returns it as a string to a variable. By default, `input()` returns data as a string, so if we need an integer or a float, we must convert it by type conversion. 1.) इनपुट():- उपयोगकर्ता से इनपुट लेने के लिए, हम `इनपुट()` फ़ंक्शन का उपयोग कर सकते हैं। यह फ़ंक्शन आमतौर पर एक मानक इनपुट डिवाइस (कीबोर्ड) से एक लाइन पढ़ता है और इसे एक स्ट्रिंग के रूप में एक वेरिएबल में लौटाता है। डिफ़ॉल्ट रूप से, `इनपुट()` डेटा को एक स्ट्रिंग के रूप में लौटाता है, इसलिए यदि हमें इंटीजर या फ्लोट की आवश्यकता है, तो हमें इसे टाईप कन्वर्जन द्वारा परिवर्तित करना होगा। 2.) print():- To display output to the user, we can use the `print()` function. 2.) प्रिंट():-  उ...

Reduce function of python

reduce function The reduce function in Python allows us to apply a specific operation to a sequence of elements and reduce them into a single value. It takes two parameters: a function and an iterable object, such as a list or tuple. Syntax reduce(function, iterable) Let's say you have a list of numbers and you want to find their sum. You can use the reduce function to achieve this in a concise manner. from functools import reduce numbers = [1, 2, 3, 4, 5] result = reduce(lambda x, y: x + y, numbers) print(result) Output 15 In this example, the reduce function takes a lambda function as the first argument, which adds two numbers together. It applies this lambda function cumulatively to the list of numbers, combining them into a single result. In the end, we get the sum of all the numbers. Let's consider another scenario. Suppose we have a list of numbers and we want to find the maximum value. The reduce function can help us achieve this with ease. from functools import reduce n...