3

@3373_vaishnavi

Factorial

Python
1 year ago
def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) # Taking user input num = int(input("Enter a number: ")) print(f"Factorial of {num} is {factorial(num)}")

Factorial number provided by user

Python
1 year ago
def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) # Example usage num = 2 print(f"Factorial of {num} is {factorial(num)}")

swap two numbers

PHP
1 year ago
<?php // Function to swap two numbers function swapNumbers(&$num1, &$num2) { // Swapping logic $temp = $num1; $num1 = $num2; $num2 = $temp; } // Example usage

Swap to variable

Python
1 year ago
# Function to swap two numbers def swap(a, b): a, b = b, a return a, b # Example usage num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) num1, num2 = swap(num1, num2)

Print number

Python
1 year ago
for i in range (1,5): for j in range(1,i+1): print(j,end=" ") print()

Find the area of circle the radius enter by the user

Python
1 year ago
Radius = float(input("Enter the Radius:")) area=3.14*Radius*Radius print("The area of circle is:",area)

WAP find area of rectangle take input of base & height from the user

Python
1 year ago
height = float(input("Enter the height:")) weidth = float(input("Enter the weidth:")) area=height* weidth print("The area of rectangle is:",area)

Find the triangle take input of height and weidth

Python
1 year ago
base = float(input("Enter the base:")) height = float(input("Enter the height:")) area=0.5*base*height print("The area of triangle is:",area)

Area of rectangle

Python
1 year ago
l=20 b=5 area=l*b print("The area of rectangle is:",area)

Nested dictionary

Python
1 year ago
my_family = { "child1":{ "name":"Raj","year":2009 }, "child2":{ "name":"Ravi","year":2010 }, "child3":{ "name":"mira","year":2011 },

Get the length of dictionary

Python
1 year ago
my_dict = {"name":"Alice","age":25} length = len(my_dict) print (length)

Merge two dictionary

Python
1 year ago
my_dict={"name":"Alice","age":25} dict1={"a":1} dict2={"b":2} dict1.update(dict2) dict1 merged_dict=dict1|dict2 print(merged_dict)

Dictionary ex

Python
1 year ago
my_dict={"name":"Alice","age":25} for key, value in my_dict.items(): print(key ,value)

Check if a key exists in a dictionary

Python
1 year ago
my_dict={"name":"john","age":30} if"name" in my_dict: print("key exist")

Input, output function in python ex.

Python
1 year ago
name=input("Enter your name:") print("Hello",name)

Local & global ex,

Python
1 year ago
x=10 def my_function(): y=5 print ("inside function:",y) my_function() print ("outside function:",x)

User defined fun in py.ex

Python
1 year ago
def greet (name): return "Hello,"+name message = greet("vaishnavi") print(message)

Clear () operation in dictionary

Python
1 year ago
my_dict = {'name': 'john', 'age': 25} my_dict.clear () print(my_dict)

Popitem() operation in dict

Python
1 year ago
my_dict = {'name': 'john', 'age': 25} item = my_dict.popitem() print(my_dict)

Pop (key) operation in dictionary

Python
1 year ago
my_dict = {'name':'john', 'age': 25} age = my_dict.pop('age') print(my_dict)