A

@Arpita3025

Convert String to Characters and Characters to String: python

Python
2 years ago
# String to characters string = "Hello" characters = list(string) print(f"The characters in the string are: {characters}") # Characters to string char_list = ['H', 'e', 'l', 'l', 'o'] string_from_characters = ''.join(char_list) print(f"The string f

Print the Inverted Pyramid:py

Python
2 years ago
def print_inverted_pyramid(rows): for i in range(rows, 0, -1): print(" " * (rows - i), end="") for j in range(1, 2 * i): print("*", end="") print() # Example usage: rows = int(input("Enter the number of rows

Find the Current Date and Time:py

Python
2 years ago
import datetime current_date_time = datetime.datetime.now() print(f"The current date and time is: {current_date_time}")

Print Star Pyramid Patterns:py

Python
2 years ago
def print_star_pyramid(rows): for i in range(1, rows + 1): print(" " * (rows - i), end="") for j in range(1, 2 * i): print("*", end="") print() # Example usage: rows = int(input("Enter the number of rows for

Print Number Pyramid Patterns: python

Python
2 years ago
def print_number_pyramid(rows): for i in range(1, rows + 1): print(" " * (rows - i), end="") for j in range(1, i + 1): print(j, end=" ") print() # Example usage: rows = int(input("Enter the number of rows for

Print Number Pyramid Patterns:py

Python
2 years ago
def print_number_pyramid(rows): for i in range(1, rows + 1): print(" " * (rows - i), end="") for j in range(1, i + 1): print(j, end=" ") print() # Example usage: rows = int(input("Enter the number of rows for

Print Duplicate Characters from a String: python

Python
2 years ago
def print_duplicate_characters(string): duplicates = [] for char in string: if string.count(char) > 1 and char not in duplicates: duplicates.append(char) return duplicates # Example usage: text = input("Enter a strin

Print Duplicate Characters from a String: python

Python
2 years ago
def print_duplicate_characters(string): duplicates = [] for char in string: if string.count(char) > 1 and char not in duplicates: duplicates.append(char) return duplicates # Example usage: text = input("Enter a strin

Print Vowels in a Given String:py

Python
2 years ago
def print_vowels(string): vowels = "aeiouAEIOU" vowel_list = [char for char in string if char in vowels] return vowel_list # Example usage: text = input("Enter a string: ") vowels = print_vowels(text) print(f"The vowels in the string ar

Print Last Character of a Given String:py

Python
2 years ago
text = input("Enter a string: ") last_character = text[-1] print(f"The last character of the string is: {last_character}")

Print Duplicate Characters from a String:py

Python
2 years ago
def print_duplicate_characters(string): duplicates = [] for char in string: if string.count(char) > 1 and char not in duplicates: duplicates.append(char) return duplicates # Example usage: text = input("Enter a strin

Print Duplicate Characters from a String:py

Python
2 years ago
def print_duplicate_characters(string): duplicates = [] for char in string: if string.count(char) > 1 and char not in duplicates: duplicates.append(char) return duplicates # Example usage: text = input("Enter a strin

Print Vowels in a Given String:py

Python
2 years ago
def print_vowels(string): vowels = "aeiouAEIOU" vowel_list = [char for char in string if char in vowels] return vowel_list # Example usage: text = input("Enter a string: ") vowels = print_vowels(text) print(f"The vowels in the string ar

Print Last Character of a Given String:py

Python
2 years ago
text = input("Enter a string: ") last_character = text[-1] print(f"The last character of the string is: {last_character}")

Perform Sum of Two Numbers without Using Arithmetic Operator (+):py

Python
2 years ago
def sum_without_operator(a, b): while b != 0: carry = a & b a = a ^ b b = carry << 1 return a # Example usage: num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: "))

Swap Two Numbers:py

Python
2 years ago
def swap_numbers(a, b): a, b = b, a return a, b # Example usage: num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num1, num2 = swap_numbers(num1, num2) print(f"After swapping: First number = {num1}, S

Calculate the Number of Characters in a Given String:py

Python
2 years ago
def count_characters(string): return len(string) # Example usage: text = input("Enter a string: ") count = count_characters(text) print(f"The number of characters in the string is: {count}")

Calculate Sum of First 'n' Numbers:py

Python
2 years ago
def calculate_sum(n): return (n * (n + 1)) // 2 # Example usage: num = int(input("Enter a number 'n' to calculate the sum of first 'n' numbers: ")) result = calculate_sum(num) print(f"The sum of first {num} numbers is: {result}")

Check if a Given Year is Leap or Not.py

Python
2 years ago
def check_leap_year(year): if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True else: return False # Example usage: year = int(input("Enter a year to check if it's leap or not: ")) if check_leap_year(year

Reverse a Given String.py

Python
2 years ago
def reverse_string(string): return string[::-1] # Example usage: text = input("Enter a string: ") reversed_text = reverse_string(text) print(f"The reversed string is: {reversed_text}")