Q.1 Create following tables using create statement with appropriate constraint and do the followings.
Q.1 Create following tables using create statement with appropriate constraint and do the followings. Q : 1 Create following tables using create statement with appropriate constraint and do thefollowings.Artist(aid, fname, lname)Paintings(pid,pname,aid,listed_price) Solution. CREATE TABLE Artist ( aid NUMBER PRIMARY KEY, fname VARCHAR2(50) NOT NULL, lname VARCHAR2(50) NOT NULL ); CREATE TABLE Paintings ( pid NUMBER […]
Write a Python program that calculates the factorial of a given number using recursion
Write a Python program that calculates the factorial of a given number using recursion SOLUTION. # Function to calculate factorial using recursion def factorial(n): if n == 0 or n == 1: # Base case return 1 return n * factorial(n – 1) # Recursive case # Taking dynamic input from the user num = […]
Write a Python program to calculate the sum of digits of a number.
Write a Python program to calculate the sum of digits of a number. SOLUTION. # Taking dynamic input from the user num = int(input(“Enter a number: “)) # Calculating the sum of digits sum_of_digits = sum(int(digit) for digit in str(abs(num))) # Convert number to string, iterate over digits, and sum them # Displaying the result […]
Write a Python program to find the mean, median, and mode of a numerical column in a DataFrame.
Write a Python program to find the mean, median, and mode of a numerical column in a DataFrame. SOLUTION . import pandas as pd # Taking dynamic input for the number of values n = int(input(“Enter the number of values: “)) # Taking dynamic input for numerical data data = [float(input(f”Enter value {i+1}: “)) for […]
Write a Python program to find the largest number in a NumPy array
Write a Python program to find the largest number in a NumPy array SOLUTION. import numpy as np # Taking dynamic input for array size n = int(input(“Enter the number of elements in the array: “)) # Taking dynamic input for array elements arr = np.array([float(input(f”Enter element {i+1}: “)) for i in range(n)]) # Finding […]
Write a program to find the number of key-value pairs in a dictionary
Write a program to find the number of key-value pairs in a dictionary SOLUTION. # Creating an empty dictionary my_dict = {} # Taking dynamic input from the user n = int(input(“Enter the number of key-value pairs: “)) # Adding key-value pairs dynamically for i in range(n): key = input(f”Enter key {i+1}: “) value = […]
Create a dictionary that contains another dictionary as a value. Access the nested dictionary value.
a SOLUTION. # Creating a dynamic nested dictionary with user input student = { “name”: input(“Enter student’s name: “), “details”: { “age”: int(input(“Enter student’s age: “)), “grade”: input(“Enter student’s grade: “), “city”: input(“Enter student’s city: “) } } # Display the entire dictionary print(“nStudent Dictionary:”, student) # Accessing nested dictionary values print(“Student’s name:”, student[“name”]) print(“Student’s […]
Create list and perform append, pop, and slice operation.
Create list and perform append, pop, and slice operation. SOLUTION. # Creating an empty list my_list = [] # Taking dynamic input from the user n = int(input(“Enter the number of elements you want in the list: “)) # Appending elements to the list for i in range(n): element = input(f”Enter element {i+1}: “) my_list.append(element) […]
Create a dictionary and access its values:
Create a dictionary and access its values: SOLUTION. # Creating a dynamic dictionary with user input student = { “name”: input(“Enter student’s name: “), “age”: int(input(“Enter student’s age: “)), “grade”: input(“Enter student’s grade: “) } # Accessing values dynamically print(“The student’s name is:”, student[“name”]) print(“The student’s grade is:”, student[“grade”])
Create a tuple with different data types and access elements:
Create a tuple with different data types and access elements: SOLUTION . # Taking dynamic input for a tuple num = int(input(“Enter an integer: “)) text = input(“Enter a string: “) decimal = float(input(“Enter a floating-point number: “)) boolean = input(“Enter a boolean value (True/False): “).strip().lower() == “true” # Creating a tuple with different data […]