diff --git a/Built-in Functions-Binary Conversion.md b/Built-in Functions-Binary Conversion.md index bedea1b87..eb4015c68 100644 --- a/Built-in Functions-Binary Conversion.md +++ b/Built-in Functions-Binary Conversion.md @@ -10,8 +10,16 @@ To write a Python program to convert the number **16** into its **binary represe ## 🧾 Program -Add Code Here +``` +a = 16 +b = bin(a) +print("Binary representation of", a, "is", b) +``` ## Output +image + ## Result + +Hence, the code is executed successfully, and the number **16** is converted into its **binary representation** `0b10000` using the built-in `bin()` function. diff --git a/Functions: Modulo Calculator.md b/Functions: Modulo Calculator.md index d32881f06..10a1f49eb 100644 --- a/Functions: Modulo Calculator.md +++ b/Functions: Modulo Calculator.md @@ -11,9 +11,20 @@ To write a Python program that defines a function which accepts two values and r 5. Call the `result` function with the user-provided values. ## 🧾 Program +``` +def result(a, b): + print("Modulo:", a % b) -Add code Here +num1 = int(input("Enter first number: ")) +num2 = int(input("Enter second number: ")) +result(num1, num2) +``` ## Output +image + + ## Result + +Hence, the code is executed successfully, and the function correctly computes and displays the **modulo** of the two input numbers. diff --git a/Lambda Function: Addition of Two Numbers.md b/Lambda Function: Addition of Two Numbers.md index 520cf0630..384029614 100644 --- a/Lambda Function: Addition of Two Numbers.md +++ b/Lambda Function: Addition of Two Numbers.md @@ -9,8 +9,20 @@ To write a Python program that defines a **lambda function** which takes two arg 3. Call the function with the user inputs and print the result. ## 🧾 Program -Add code here +``` +a = int(input("Enter first number: ")) +b = int(input("Enter second number: ")) + +f = lambda x, y: x + y +result = f(a, b) + +print("Sum:", result) +``` ## Output +image + ## Result + +Hence, the code is executed successfully, and the **lambda function** correctly computes and displays the sum of the two input numbers. diff --git a/Looping(Patterns)-Pascal's Triangle Generator.md b/Looping(Patterns)-Pascal's Triangle Generator.md index 1a7dec6c3..27f489c36 100644 --- a/Looping(Patterns)-Pascal's Triangle Generator.md +++ b/Looping(Patterns)-Pascal's Triangle Generator.md @@ -27,9 +27,22 @@ To write a Python program that generates **Pascal's Triangle** using numbers. Th --- ## 🧪 Program -Add Code Here +``` +from math import factorial + +rows = int(input("Enter number of rows: ")) + +for i in range(rows): + print(" " * (rows - i), end="") + for j in range(i + 1): + print(factorial(i) // (factorial(j) * factorial(i - j)), end=" ") + print() +``` ## Sample Output +image + ## Result +Hence, the code is executed successfully, and the Pascal’s Triangle is generated correctly for the user-specified number of rows. diff --git a/Loops-Palindrome Number check.md b/Loops-Palindrome Number check.md index 15dd6d692..1ab5401e1 100644 --- a/Loops-Palindrome Number check.md +++ b/Loops-Palindrome Number check.md @@ -16,7 +16,24 @@ To write a Python program that checks whether a given number is a **palindrome** - Else, print that it is not a palindrome. ## 🧾 Program -Add code Here +``` +num = int(input("Enter a number: ")) +temp = num +rev = 0 + +while temp > 0: + rev = (10 * rev) + temp % 10 + temp = temp // 10 + +if rev == num: + print(num, "is a palindrome") +else: + print(num, "is not a palindrome") +``` ## Output +image + ## Result + +Hence, the code is executed successfully, and the program correctly checks whether the entered number is a palindrome.