Comprehensive guide to all functions in the ncert_learn Python module.
Important Notice: While this documentation includes only the most useful functions for Class 12 CS students, the module includes additional features that will be documented later as more time becomes available. Below is an overview of the main features included in ncert_learn
:
ncert_learn
Created By: Muhammed Shafin P.
Overview: The ncert_learn
module is a comprehensive Python package designed to support NCERT Class 12 Computer Science students. It offers a wide range of utility functions across various topics, including Python programming, MySQL database interactions, mathematical operations, data structures, network security, and more.
Platform Recommendation: This module has a wide range of functionalities, but it is optimized for Windows to ensure all features work properly and efficiently. While it is possible to use the module on other operating systems, for the full experience and to ensure optimal performance, we recommend using Windows.
get_ip_details
and get_phone_number_details
for fetching IP geolocation data and phone number details, respectively.Monero was selected for its privacy, decentralization, hardware compatibility, and efficiency in mining, making it an ideal choice for this educational module.
ncert_learn
Installation: To install the latest version of ncert_learn
, you can use pip by running the following command in your terminal:
pip install ncert_learn
Alternatively, to install manually, clone the repository and run the following commands:
git clone https://github.com/hejhdiss/ncert_learn.git
cd ncert_learn
python setup.py install
Upgrade: To upgrade to the latest version, use the following pip command:
pip install --upgrade ncert_learn
All the functionalities within ncert_learn
are educational tools designed for learning purposes. Some tools require specific hardware and configurations to work efficiently, such as GPU mining or database management tools. Please read all instructions before using any features.
We're excited to share that `ncert_learn` has surpassed **6,000 downloads** in just **14 days**! 🌟 This milestone reflects the growing popularity and trust in our module for Class 12 students and Python developers alike.
With its powerful features in fields like **data structures**, **cryptography**, and now **Monero mining**, this achievement is a testament to the effectiveness and relevance of `ncert_learn` in helping students and professionals build their skills and projects.
Thank you to everyone who has downloaded and supported the module. The journey is just beginning—stay tuned for even more exciting updates! 🚀
Network Security & Utilities: This module includes functionalities for SQL injection testing, network scanning, and local service management. It integrates tools such as sqlmap, nmap, and XAMPP to help users perform security-related tasks and manage services effectively.
Tested Platforms:
Tested Python Versions:
Build Information:
The ncert_learn
module has been rigorously built and tested on the above platforms and Python versions to ensure compatibility and reliability.
The ncert_learn
module will continue to be updated with new features and improvements as time allows. The documentation for additional functions will be added in the future.
We welcome contributions to the project. Please fork the repository, create a feature branch, and submit a pull request for review. For any issues or suggestions, feel free to open an issue on the GitHub repository.
A big thank you to the contributors and the community for their support in making this release possible. Special thanks to those who helped with Monero mining features.
For more information, visit the GitHub repository : GitHub Repository.
You can also find ncert_learn on PyPI.
sqlmap_scan(url, **kwargs)
Description: Executes the SQLmap scan command to test a URL for SQL injection vulnerabilities with additional parameters.
Parameters:
url
: str - The URL to scan for SQL injection vulnerabilities.kwargs
: dict - Additional SQLmap options passed as key-value pairs (e.g., `--cookie`, `--proxy`).Returns: None - Logs the result of the scan.
Example Usage:
from ncert_learn import sqlmap_scan
sqlmap_scan("http://example.com", --cookie="name=value", --level=5)
nmap_scan(target, arguments)
Description: Executes a basic Nmap scan on a target with the specified arguments to identify open ports and services.
Parameters:
target
: str - The target IP address or hostname to scan.arguments
: str - The Nmap command-line arguments for the scan (e.g., `-p 80,443` for scanning ports 80 and 443).Returns: None - Logs the scan results including host, protocol, and open ports.
Example Usage:
from ncert_learn import nmap_scan
nmap_scan("192.168.1.1", "-p 22,80")
get_ip_details(ip_address)
Description: Fetches details about an IP address such as location, region, and more, by querying an IP geolocation service.
Parameters:
ip_address
: str - The IP address for which details are to be fetched.Returns: dict - A dictionary containing IP details (e.g., city, region, country), or an error message if fetching fails.
Example Usage:
from ncert_learn import get_ip_details
ip_info = get_ip_details("8.8.8.8")
print(ip_info)
get_phone_number_details(phone_number)
Description: Fetches details about a phone number including its country, carrier, and validity.
Parameters:
phone_number
: str - The phone number to be analyzed, including the country code.Returns: dict - A dictionary containing the country, carrier, and validity of the phone number, or an error message if the number is invalid.
Example Usage:
from ncert_learn import get_phone_number_details
phone_info = get_phone_number_details("+14155552671")
print(phone_info)
extract_text_from_pdf(pdf_path)
Description: Extracts text from a PDF file at the specified path.
Parameters:
pdf_path
: str - The path to the PDF file from which text is to be extracted.Returns: str - The extracted text from the PDF file.
Example Usage:
from ncert_learn import extract_text_from_pdf
pdf_text = extract_text_from_pdf("document.pdf")
print(pdf_text)
save_text_to_file(text, output_file)
Description: Saves the provided text to a text file with UTF-8 encoding at the specified location.
Parameters:
text
: str - The text to be saved to the file.output_file
: str - The path to the text file where the text will be saved.Returns: None - The function writes the text to the output file and does not return any value.
Example Usage:
from ncert_learn import save_text_to_file
text_to_save = "Extracted text from PDF"
save_text_to_file(text_to_save, "output.txt")
get_mining_pool_info_monero()
Description: Prints information about popular Monero mining pools, including pool names and ports.
Returns: None - This function prints details of Monero mining pools to the console.
Example Usage:
from ncert_learn import get_mining_pool_info_monero
get_mining_pool_info_monero()
Output Example:
Monero Mining Pools and Ports:
MineXMR:
URL: rx.unmineable.com
Ports: 3333, 443
----------------------------------------
SupportXMR:
URL: pool.supportxmr.com
Ports: 3333, 443
----------------------------------------
F2Pool:
URL: monero.f2pool.com
Ports: 13531, 13532
----------------------------------------
MoneroOcean:
URL: pool.moneroocean.stream
Ports: 10128, 10129
----------------------------------------
NanoPool:
URL: xmr-eu1.nanopool.org
Ports: 14444, 14443
----------------------------------------
XMRigPool:
URL: xmrpool.eu
Ports: 3333, 443
----------------------------------------
Poolin:
URL: xmr.poolin.com
Ports: 8888, 443
----------------------------------------
calculate_profitability_monero(hashrate, power_cost, power_consumption)
Description: Calculates profitability based on hashrate and power costs for Monero mining.
Args:
hashrate
: float - Mining hashrate in H/s.power_cost
: float - Electricity cost per kWh.power_consumption
: float - Power consumption in watts.Returns: float - Estimated profitability in USD per day.
Example Usage:
from ncert_learn import calculate_profitability_monero
# Example values for hashrate (H/s), power cost ($/kWh), and power consumption (W)
profitability = calculate_profitability_monero(500000, 0.12, 100)
print(f'Profitability: {profitability} USD/day')
mine_monero()
Description: Initiates Monero mining by collecting user inputs for wallet address, pool URL, and CPU threads, then starts and monitors the mining process.
Returns: None - Starts the mining process and monitors the output from the mining process.
Example Usage:
from ncert_learn import mine_monero
# Start Monero mining by collecting user input
mine_monero()
mine_monero_wallet_saved()
Description: Initiates Monero mining by collecting user inputs for wallet address, mining pool URL, and CPU threads. It saves the wallet address in an encrypted format and allows the user to change it during the mining process. The miner is then started, and its output is monitored.
Returns: None - Starts and monitors the mining process, with an option to change the wallet address during the mining process.
Example Usage:
from ncert_learn import mine_monero_wallet_saved
# Start Monero mining with a saved wallet address
mine_monero_wallet_saved()
mine_monero_advanced_mode()
Description: Initiates Monero mining in advanced mode by setting up a miner with encrypted wallet address, pool URL, and thread count. The configuration is saved securely in a file ('miningdata') for future use. Users can choose to change wallet address, pool URL, and thread count during the process.
Returns: None - Starts and monitors the mining process in advanced mode, with the option to save or modify the mining configuration.
Example Usage:
from ncert_learn import mine_monero_advanced_mode
# Start advanced mode Monero mining with saved configuration
mine_monero_advanced_mode()
mine_monero_cuda()
Description: Initiates Monero mining by setting up a miner and monitoring its output. The function collects user inputs for the Monero wallet address, mining pool URL, and the number of CPU threads to use. It then starts the mining process using these inputs and monitors the output from the mining process. If an error occurs during monitoring, it terminates the miner process.
Returns: None - Starts and monitors the mining process using GPU with CUDA, terminating on error.
Example Usage:
from ncert_learn import mine_monero_cuda
# Start Monero mining using GPU with CUDA
mine_monero_cuda()
mine_monero_opencl()
Description: Initiates Monero mining by setting up a miner and monitoring its output. The function collects user inputs for the Monero wallet address, mining pool URL, and the number of CPU threads to use. It then starts the mining process using these inputs and monitors the output from the mining process. If an error occurs during monitoring, it terminates the miner process.
Returns: None - Starts and monitors the mining process using OpenCL, terminating on error.
Example Usage:
from ncert_learn import mine_monero_opencl
# Start Monero mining using OpenCL
mine_monero_opencl()
xmrig_benchmark()
Description: Runs XMRig in benchmark mode using the specified executable and captures the output. This function benchmarks the mining algorithm (default is "rx/0" for RandomX) and threads, returning benchmark results such as hashrate and details.
Parameters:
Returns: A dictionary containing benchmark results such as hashrate and details.
Example Usage:
from ncert_learn import xmrig_benchmark
# Run XMRig benchmark with default settings
result = xmrig_benchmark()
print(result)
install_and_setup_nmap()
Description: Handles the installation of Nmap while ensuring administrator privileges are met. Note: This function is designed for Windows operating systems only.
Parameters:
Returns: None
Steps Performed:
Platform: Windows
Example Usage:
from ncert_learn import install_and_setup_nmap
# Install and set up Nmap (Windows only)
install_and_setup_nmap()
areaofcircle(radius)
Description: Calculates the area of a circle given its radius.
Parameters:
radius
: float - The radius of the circle.Returns: float - The area of the circle.
Example Usage:
from ncert_learn import areaofcircle
area = areaofcircle(5)
print(f'Area of circle: {area}')
areaoftriangle(base, height)
Description: Calculates the area of a triangle given its base and height.
Parameters:
base
: float - The base length of the triangle.height
: float - The height of the triangle.Returns: float - The area of the triangle.
Example Usage:
from ncert_learn import areaoftriangle
area = areaoftriangle(10, 5)
print(f'Area of triangle: {area}')
areaofsquare(side)
Description: Calculates the area of a square given the length of its side.
Parameters:
side
: float - The length of the side of the square.Returns: float - The area of the square.
Example Usage:
from ncert_learn import areaofsquare
area = areaofsquare(4)
print(f'Area of square: {area}')
areaofrectangle(length, width)
Description: Calculates the area of a rectangle given its length and width.
Parameters:
length
: float - The length of the rectangle.width
: float - The width of the rectangle.Returns: float - The area of the rectangle.
Example Usage:
from ncert_learn import areaofrectangle
area = areaofrectangle(5, 10)
print(f'Area of rectangle: {area}')
areaofpolygon(noofsides, lengthofeachside)
Description: Calculates the area of a polygon given its number of sides and the length of its side.
Parameters:
noofsides
: int - The number of sides of the polygon.lengthofeachside
: float - The length of each side of the polygon.Returns: float or str - The area of the polygon, or False
if the number of sides is less than 3.
Example Usage:
from ncert_learn import areaofpolygon
area = areaofpolygon(6, 5)
print(f'Area of polygon: {area}')
isbinaryfile(file_path)
Description: Checks if a file is a binary file.
Parameters:
file_path
: str - Path to the file.Returns: bool - True
if the file is binary, False
otherwise.
Example Usage:
from ncert_learn import isbinaryfile
is_binary = isbinaryfile('file.bin')
print(f'Is binary: {is_binary}')
copybinaryfromonetoanother(src, dest)
Description: Copies the binary content from the file given by path src
to the file given by path dest
.
Parameters:
src
: str - The path of the file to copy from.dest
: str - The path of the file to copy to.Returns: bool - True if the copy operation is successful, False otherwise.
Example Usage:
from ncert_learn import copybinaryfromonetoanother
result = copybinaryfromonetoanother('source.bin', 'destination.bin')
print(f'Copy successful: {result}')
openbinaryfile(file_path)
Description: Opens the binary file given by path file_path
to set it as the current working file.
Parameters:
file_path
: str - The path of the file to open.Returns: bool - True if the file is opened successfully, False otherwise.
Example Usage:
from ncert_learn import openbinaryfile
result = openbinaryfile('file.bin')
print(f'File opened: {result}')
addtextobinaryfile(byte_data)
Description: Appends a sequence of bytes to the binary file opened by openbinaryfile()
function.
Parameters:
byte_data
: bytes - A sequence of bytes to append.Returns: bool - True if the bytes are appended successfully, False otherwise.
Example Usage:
from ncert_learn import addtextobinaryfile
result = addtextobinaryfile(b'Hello, world!')
print(f'Bytes appended: {result}')
readbinaryfile()
Description: Reads the contents of the binary file opened by openbinaryfile()
function.
Returns: bytes - The contents of the file as bytes.
Example Usage:
from ncert_learn import readbinaryfile
data = readbinaryfile()
print(f'File content: {data}')
clearbinaryfile()
Description: Clears the contents of the binary file opened by openbinaryfile()
function.
Example Usage:
from ncert_learn import clearbinaryfile
clearbinaryfile()
print('File contents cleared.')
readbinaryspecificchunk(offset, size)
Description: Reads a specific chunk from the binary file opened by openbinaryfile()
function.
Parameters:
offset
: int - The starting position to read from the file.size
: int - The number of bytes to read.Returns: bytes - The content of the specified chunk as bytes if successful, False if any error occurs.
Example Usage:
from ncert_learn import readbinaryspecificchunk
chunk = readbinaryspecificchunk(0, 10)
print(f'Chunk data: {chunk}')
overwritebinaryfile(new_data)
Description: Overwrites the contents of the binary file opened by openbinaryfile()
with new data.
Parameters:
new_data
: bytes - The new content to write to the binary file.Returns: bool - True if the file is overwritten successfully, False otherwise.
Example Usage:
from ncert_learn import overwritebinaryfile
result = overwritebinaryfile(b'New binary content')
print(f'File overwritten: {result}')
binary_file_operations_advanced_mode(folder_path, operation, file_name=None, new_name=None, data=None)
Description: Perform various binary file operations in a specified folder, such as create, write, append, read, clear, delete, rename, or list files.
Parameters:
folder_path
: str - Path to the folder where the operations will be performed.operation
: str - The operation to perform. Supported operations: 'create', 'write', 'append', 'read', 'clear', 'delete', 'rename', 'list_files'.file_name
: str - The file name for the operation (optional).new_name
: str - New name for the file (used in 'rename').data
: bytes - Binary data for 'write' or 'append' operations (optional).Returns: bool - For 'read': Returns file content (bytes) or False on error. For 'list_files': Returns a list of files in the folder or False on error. For other operations: Returns True if successful, False if failed.
Example Usage:
from ncert_learn import binary_file_operations_advanced_mode
binary_file_operations_advanced_mode('/path/to/folder', 'create', 'new_file.bin')
integertobinary(s)
Description: Converts an integer to binary format.
Parameters:
s
: int - The integer to convert.Returns: int - The binary representation of the integer if the input is an integer, otherwise False
.
Example Usage:
from ncert_learn import integertobinary
binary_representation = integertobinary(10)
print(f'Binary representation: {binary_representation}')
integertooctal(s)
Description: Converts an integer to octal format.
Parameters:
s
: int - The integer to convert.Returns: str - The octal representation of the integer if the input is an integer, otherwise False
.
Example Usage:
from ncert_learn import integertooctal
octal_representation = integertooctal(10)
print(f'Octal representation: {octal_representation}')
integertohexadecimal(s)
Description: Converts an integer to hexadecimal format.
Parameters:
s
: int - The integer to convert.Returns: str - The hexadecimal representation of the integer if the input is an integer, otherwise False
.
Example Usage:
from ncert_learn import integertohexadecimal
hexadecimal_representation = integertohexadecimal(10)
print(f'Hexadecimal representation: {hexadecimal_representation}')
binarytointeger(s)
Description: Converts a binary number to an integer.
Parameters:
s
: int - The binary number to convert.Returns: int - The integer representation of the binary number if the input is an integer, otherwise False
.
Example Usage:
from ncert_learn import binarytointeger
integer_representation = binarytointeger(1010)
print(f'Integer representation: {integer_representation}')
iscsvfile(file_path)
Description: Checks if a file is a CSV file.
Parameters:
file_path
: str - The path to the file.Returns: bool - True if the file is a CSV file, False otherwise.
Example Usage:
from ncert_learn import iscsvfile
is_csv = iscsvfile('file.csv')
print(is_csv) # Output: True or False
copycsvfromonetoanother(src, dest)
Description: Copies the CSV content from the file given by path src
to the file given by path dest
.
Parameters:
src
: str - The path of the file to copy from.dest
: str - The path of the file to copy to.Returns: bool - True if the copy operation is successful, False otherwise.
Example Usage:
from ncert_learn import copycsvfromonetoanother
success = copycsvfromonetoanother('source.csv', 'destination.csv')
print(success) # Output: True or False
opencsvfile(file_path)
Description: Opens the CSV file given by path file_path
to set it as the current working file.
Parameters:
file_path
: str - The path of the file to open.Returns: bool - True if the file is opened successfully, False otherwise.
Example Usage:
from ncert_learn import opencsvfile
success = opencsvfile('data.csv')
print(success) # Output: True or False
addrowtocsv(row_data)
Description: Appends a row of data to the CSV file opened by opencsvfile()
.
Parameters:
row_data
: list - A list of values representing a row to append.Returns: bool - True if the row is appended successfully, False otherwise.
Example Usage:
from ncert_learn import addrowtocsv
success = addrowtocsv(['value1', 'value2', 'value3'])
print(success) # Output: True or False
readcsvfile()
Description: Reads the contents of the CSV file opened by opencsvfile()
.
Returns: list - A list of rows, where each row is a list of column values.
Example Usage:
from ncert_learn import readcsvfile
rows = readcsvfile()
print(rows) # Output: List of rows in the CSV file
clearcsvfile()
Description: Clears the contents of the CSV file opened by opencsvfile()
.
Returns: None
Example Usage:
from ncert_learn import clearcsvfile
clearcsvfile()
print('CSV file cleared.') # No return value
readcsvspecificline(line_number)
Description: Reads a specific line from the CSV file opened by opencsvfile()
.
Parameters:
line_number
: int - The line number to read from the file (1-based index).Returns: list - The content of the specified line as a list if successful, False if the line number is out of range or an error occurs.
Example Usage:
from ncert_learn import readcsvspecificline
line = readcsvspecificline(2)
print(line) # Output: List of values from line 2 or False
overwritecsvfile(rows)
Description: Overwrites the contents of the CSV file opened by opencsvfile()
.
Parameters:
rows
: list - A list of rows, where each row is a list of column values.Returns: bool - True if the file is overwritten successfully, False otherwise.
Example Usage:
from ncert_learn import overwritecsvfile
success = overwritecsvfile([['value1', 'value2'], ['value3', 'value4']])
print(success) # Output: True or False
csv_file_operations_advanced_mode(folder_path, operation, file_name=None, new_name=None, data=None)
Description: Performs various CSV file operations in a specified folder. Supported operations: 'create', 'write', 'append', 'read', 'clear', 'delete', 'rename', 'list_files'.
Parameters:
folder_path
: str - Path of the folder where the files are stored.operation
: str - The operation to perform (e.g., 'create', 'write', etc.).file_name
: str (optional) - The name of the CSV file to operate on.new_name
: str (optional) - The new name for renaming.data
: list (optional) - The data to write or append.Returns: bool - True if the operation is successful, False otherwise.
Example Usage:
from ncert_learn import csv_file_operations_advanced_mode
csv_file_operations_advanced_mode('/path/to/folder', 'create', 'newfile.csv')
csv_file_operations_advanced_mode('/path/to/folder', 'write', 'newfile.csv', data=[['column1', 'column2']])
dict_add_key_value(d, key, value)
Description: Adds a key-value pair to the dictionary.
Parameters:
d
: dict - The dictionary to which the key-value pair will be added.key
: str - The key to be added.value
: any - The value corresponding to the key.Returns: dict - The updated dictionary.
Example Usage:
from ncert_learn import dict_add_key_value
my_dict = {'a': 1}
dict_add_key_value(my_dict, 'b', 2)
print(my_dict)
dict_remove_key(d, key)
Description: Removes a key-value pair from the dictionary.
Parameters:
d
: dict - The dictionary from which the key-value pair will be removed.key
: str - The key of the pair to be removed.Returns: dict or bool - The updated dictionary or False
if the key is not found.
Example Usage:
from ncert_learn import dict_remove_key
my_dict = {'a': 1, 'b': 2}
dict_remove_key(my_dict, 'a')
print(my_dict)
dict_get_value(d, key)
Description: Retrieves the value associated with a key in the dictionary.
Parameters:
d
: dict - The dictionary from which the value will be retrieved.key
: str - The key whose associated value is to be retrieved.Returns: any - The value associated with the key, or None
if the key is not found.
Example Usage:
from ncert_learn import dict_get_value
my_dict = {'a': 1, 'b': 2}
value = dict_get_value(my_dict, 'b')
print(value)
dict_update_value(d, key, value)
Description: Updates the value of an existing key in the dictionary.
Parameters:
d
: dict - The dictionary to be updated.key
: str - The key whose value will be updated.value
: any - The new value to associate with the key.Returns: dict - The updated dictionary, or False
if the key is not found.
Example Usage:
from ncert_learn import dict_update_value
my_dict = {'a': 1, 'b': 2}
dict_update_value(my_dict, 'a', 10)
print(my_dict)
dict_contains_key(d, key)
Description: Checks if the dictionary contains a specific key.
Parameters:
d
: dict - The dictionary to check.key
: str - The key to check for existence.Returns: bool - True
if the key exists, otherwise False
.
Example Usage:
from ncert_learn import dict_contains_key
my_dict = {'a': 1, 'b': 2}
contains = dict_contains_key(my_dict, 'a')
print(contains)
dict_get_all_keys(d)
Description: Returns a list of all keys in the dictionary.
Parameters:
d
: dict - The dictionary to get keys from.Returns: list - A list of all keys in the dictionary.
Example Usage:
from ncert_learn import dict_get_all_keys
my_dict = {'a': 1, 'b': 2}
keys = dict_get_all_keys(my_dict)
print(keys)
dict_get_all_values(d)
Description: Returns a list of all values in the dictionary.
Parameters:
d
: dict - The dictionary to get values from.Returns: list - A list of all values in the dictionary.
Example Usage:
from ncert_learn import dict_get_all_values
my_dict = {'a': 1, 'b': 2}
values = dict_get_all_values(my_dict)
print(values)
dict_clear(d)
Description: Clears all key-value pairs from the dictionary.
Parameters:
d
: dict - The dictionary to clear.Returns: None - The dictionary is modified in-place.
Example Usage:
from ncert_learn import dict_clear
my_dict = {'a': 1, 'b': 2}
dict_clear(my_dict)
print(my_dict)
dict_copy(d)
Description: Returns a shallow copy of the dictionary.
Parameters:
d
: dict - The dictionary to copy.Returns: dict - A shallow copy of the dictionary.
Example Usage:
from ncert_learn import dict_copy
my_dict = {'a': 1, 'b': 2}
copy_dict = dict_copy(my_dict)
print(copy_dict)
dict_items(d)
Description: Returns a list of all key-value pairs as tuples.
Parameters:
d
: dict - The dictionary to retrieve key-value pairs from.Returns: list - A list of tuples where each tuple is a key-value pair.
Example Usage:
from ncert_learn import dict_items
my_dict = {'a': 1, 'b': 2}
items = dict_items(my_dict)
print(items)
dict_pop_item(d, key)
Description: Removes and returns the value for a specified key.
Parameters:
d
: dict - The dictionary to pop the item from.key
: str - The key to remove from the dictionary.Returns: any - The value of the popped key, or None
if the key is not found.
Example Usage:
from ncert_learn import dict_pop_item
my_dict = {'a': 1, 'b': 2}
value = dict_pop_item(my_dict, 'a')
print(value)
dict_update(d, other_dict)
Description: Updates the dictionary with another dictionary's key-value pairs.
Parameters:
d
: dict - The dictionary to be updated.other_dict
: dict - The dictionary whose key-value pairs will be added to d
.Returns: dict - The updated dictionary.
Example Usage:
from ncert_learn import dict_update
my_dict = {'a': 1, 'b': 2}
other_dict = {'c': 3, 'd': 4}
dict_update(my_dict, other_dict)
print(my_dict)
dict_setdefault(d, key, default=None)
Description: Returns the value of the key if it exists, otherwise inserts the key with the default value.
Parameters:
d
: dict - The dictionary to operate on.key
: str - The key to check.default
: any - The value to insert if the key doesn't exist (default is None
).Returns: any - The value of the key, or the default value if the key does not exist.
Example Usage:
from ncert_learn import dict_setdefault
my_dict = {'a': 1, 'b': 2}
value = dict_setdefault(my_dict, 'c', 3)
print(my_dict)
print(value)
dict_fromkeys(keys, value=None)
Description: Creates a new dictionary with the specified keys and a default value.
Parameters:
keys
: list - A list of keys for the new dictionary.value
: any - The default value for each key (default is None
).Returns: dict - A new dictionary with the specified keys and values.
Example Usage:
from ncert_learn import dict_fromkeys
keys = ['a', 'b', 'c']
new_dict = dict_fromkeys(keys, 0)
print(new_dict)
dict_get_key_with_max_value(d)
Description: Returns the key with the maximum value in the dictionary.
Parameters:
d
: dict - The dictionary to search.Returns: str - The key with the maximum value, or None
if the dictionary is empty.
Example Usage:
from ncert_learn import dict_get_key_with_max_value
my_dict = {'a': 1, 'b': 5, 'c': 3}
key = dict_get_key_with_max_value(my_dict)
print(key)
dict_get_key_with_min_value(d)
Description: Returns the key with the minimum value in the dictionary.
Parameters:
d
: dict - The dictionary to search.Returns: str - The key with the minimum value, or None
if the dictionary is empty.
Example Usage:
from ncert_learn import dict_get_key_with_min_value
my_dict = {'a': 1, 'b': 5, 'c': 3}
key = dict_get_key_with_min_value(my_dict)
print(key)
checkprime(a)
Description: Determines if a number a
is prime.
Parameters:
a
: int - The number to check for primality.Returns: bool - True if the number is prime, False otherwise.
Example Usage:
from ncert_learn import checkprime
is_prime = checkprime(7)
print(is_prime) # True
factors(a)
Description: Returns all the factors of a number a
.
Parameters:
a
: int - The number for which factors are required.Returns: tuple - A tuple of all the factors of the number.
Example Usage:
from ncert_learn import factors
factors_of_number = factors(12)
print(factors_of_number) # (1, 2, 3, 4, 6, 12)
len_fibonacci(a)
Description: Generates the first a
Fibonacci numbers.
Parameters:
a
: int - The number of Fibonacci numbers to generate.Returns: tuple - A tuple of the first a
Fibonacci numbers.
Example Usage:
from ncert_learn import len_fibonacci
fibonacci_series = len_fibonacci(10)
print(fibonacci_series) # (-1, 1, 0, 1, 1, 2, 3, 5, 8, 13)
checkarmstrong(a)
Description: Checks if a number a
is an Armstrong number.
Parameters:
a
: int - The number to check.Returns: bool - True if the number is an Armstrong number, False otherwise.
Example Usage:
from ncert_learn import checkarmstrong
is_armstrong = checkarmstrong(153)
print(is_armstrong) # True
intreverse(a)
Description: Reverses the digits of a number a
.
Parameters:
a
: int - The number to reverse.Returns: int - The reversed number.
Example Usage:
from ncert_learn import intreverse
reversed_number = intreverse(1234)
print(reversed_number) # 4321
checkpalindrome(a)
Description: Checks if a number a
is a palindrome.
Parameters:
a
: int - The number to check.Returns: bool - True if the number is a palindrome, False otherwise.
Example Usage:
from ncert_learn import checkpalindrome
is_palindrome = checkpalindrome(121)
print(is_palindrome) # True
checkstrong(a)
Description: Checks if a number a
is a strong number.
Parameters:
a
: int - The number to check.Returns: bool - True if the number is a strong number, False otherwise.
Example Usage:
from ncert_learn import checkstrong
is_strong = checkstrong(6)
print(is_strong) # True
checkniven(a)
Description: Checks if a number a
is a Niven number.
Parameters:
a
: int - The number to check.Returns: bool - True if the number is a Niven number, False otherwise.
Example Usage:
from ncert_learn import checkniven
is_niven = checkniven(18)
print(is_niven) # True
prime(z)
Description: Determines all prime numbers up to a given number z
.
Parameters:
z
: int - The upper limit to check for prime numbers.Returns: tuple or int - A tuple containing all prime numbers up to z
, or -1 if no prime numbers are found.
Example Usage:
from ncert_learn import prime
primes = prime(20)
print(f'Prime numbers up to 20: {primes}')
armstrong(z)
Description: Determines all Armstrong numbers up to a given number z
.
Parameters:
z
: int - The upper limit to check for Armstrong numbers.Returns: tuple or int - A tuple containing all Armstrong numbers up to z
, or -1 if no Armstrong numbers are found.
Example Usage:
from ncert_learn import armstrong
armstrong_numbers = armstrong(1000)
print(f'Armstrong numbers up to 1000: {armstrong_numbers}')
strong(z)
Description: Determines all strong numbers up to a given number z
.
Parameters:
z
: int - The upper limit to check for strong numbers.Returns: tuple or int - A tuple containing all strong numbers up to z
, or -1 if no strong numbers are found.
Example Usage:
from ncert_learn import strong
strong_numbers = strong(1000)
print(f'Strong numbers up to 1000: {strong_numbers}')
niven(z)
Description: Determines all Niven numbers up to a given number z
.
Parameters:
z
: int - The upper limit to check for Niven numbers.Returns: tuple or int - A tuple containing all Niven numbers up to z
, or -1 if no Niven numbers are found.
Example Usage:
from ncert_learn import niven
niven_numbers = niven(1000)
print(f'Niven numbers up to 1000: {niven_numbers}')
palindrome(z)
Description: Finds all palindrome numbers up to a given number z
.
Parameters:
z
: int - The upper limit to find palindrome numbers.Returns: tuple or int - A tuple containing all palindrome numbers up to z
, or -1 if no palindrome numbers are found.
Example Usage:
from ncert_learn import palindrome
palindromes = palindrome(1000)
print(f'Palindrome numbers up to 1000: {palindromes}')
len_prime(yt)
Description: Generates the first yt
prime numbers.
Parameters:
yt
: int - The number of prime numbers to generate.Returns: tuple or int - A tuple containing the first yt
prime numbers, or -1 if no prime numbers are found.
Example Usage:
from ncert_learn import len_prime
primes = len_prime(10)
print(f'First 10 prime numbers: {primes}')
len_armstrong(yt)
Description: Generates the first yt
Armstrong numbers.
Parameters:
yt
: int - The number of Armstrong numbers to generate.Returns: tuple or int - A tuple containing the first yt
Armstrong numbers, or -1 if no Armstrong numbers are found.
Example Usage:
from ncert_learn import len_armstrong
armstrong_numbers = len_armstrong(10)
print(f'First 10 Armstrong numbers: {armstrong_numbers}')
len_strong(yt)
Description: Generates the first yt
strong numbers. A strong number is a number that is equal to the sum of all its proper divisors.
Parameters:
yt
: int - The number of strong numbers to generate.Returns: tuple or int - A tuple containing the first yt
strong numbers, or -1 if no strong numbers are found.
Example Usage:
from ncert_learn import len_strong
strong_numbers = len_strong(5)
print(strong_numbers)
len_niven(yt)
Description: Generates the first yt
Niven numbers. A Niven number is a number that is divisible by the sum of its digits.
Parameters:
yt
: int - The number of Niven numbers to generate.Returns: tuple or int - A tuple containing the first yt
Niven numbers, or -1 if no Niven numbers are found.
Example Usage:
from ncert_learn import len_niven
niven_numbers = len_niven(5)
print(niven_numbers)
len_palindrome(yt)
Description: Generates the first yt
palindrome numbers. A palindrome is a number that reads the same backward as forward.
Parameters:
yt
: int - The number of palindrome numbers to generate.Returns: tuple or int - A tuple containing the first yt
palindrome numbers, or -1 if no palindrome numbers are found.
Example Usage:
from ncert_learn import len_palindrome
palindrome_numbers = len_palindrome(5)
print(palindrome_numbers)
checkeven(a)
Description: Checks if a number is even.
Parameters:
a
: int - The number to check.Returns: bool - True
if the number is even, False
otherwise.
Example Usage:
from ncert_learn import checkeven
is_even = checkeven(4)
print(is_even) # True
checkodd(a)
Description: Checks if a number is odd.
Parameters:
a
: int - The number to check.Returns: bool - True
if the number is odd, False
otherwise.
Example Usage:
from ncert_learn import checkodd
is_odd = checkodd(5)
print(is_odd) # True
checkzero(a)
Description: Checks if a number is zero.
Parameters:
a
: int - The number to check.Returns: bool - True
if the number is zero, False
otherwise.
Example Usage:
from ncert_learn import checkzero
is_zero = checkzero(0)
print(is_zero) # True
checknegative(a)
Description: Checks if a number is negative.
Parameters:
a
: int - The number to check.Returns: bool - True
if the number is negative, False
otherwise.
Example Usage:
from ncert_learn import checknegative
is_negative = checknegative(-1)
print(is_negative) # True
checkpositive(a)
Description: Checks if a number is positive.
Parameters:
a
: int - The number to check.Returns: bool - True
if the number is positive, False
otherwise.
Example Usage:
from ncert_learn import checkpositive
is_positive = checkpositive(2)
print(is_positive) # True
list_append_item(lst, item)
Description: Appends an item to the list.
Parameters:
lst
: list - The list to which the item will be added.item
: any - The item to append to the list.Returns: list - The updated list.
Example Usage:
from ncert_learn import list_append_item
lst = [1, 2, 3]
updated_lst = list_append_item(lst, 4)
print(updated_lst) # [1, 2, 3, 4]
list_remove_item(lst, item)
Description: Removes the first occurrence of an item from the list.
Parameters:
lst
: list - The list from which the item will be removed.item
: any - The item to remove from the list.Returns: list or bool - The updated list if the item was removed, or False
if the item was not found.
Example Usage:
from ncert_learn import list_remove_item
lst = [1, 2, 3]
updated_lst = list_remove_item(lst, 2)
print(updated_lst) # [1, 3]
list_insert_item(lst, index, item)
Description: Inserts an item at a specified index in the list.
Parameters:
lst
: list - The list to insert the item into.index
: int - The index at which to insert the item.item
: any - The item to insert into the list.Returns: list - The updated list.
Example Usage:
from ncert_learn import list_insert_item
lst = [1, 3, 4]
updated_lst = list_insert_item(lst, 1, 2)
print(updated_lst) # [1, 2, 3, 4]
list_pop_item(lst, index=-1)
Description: Pops an item from the list at the specified index.
Parameters:
lst
: list - The list to pop the item from.index
: int, optional - The index at which to pop the item (default is -1, which pops the last item).Returns: any or bool - The item that was popped, or False
if the index is out of range.
Example Usage:
from ncert_learn import list_pop_item
lst = [1, 2, 3]
popped_item = list_pop_item(lst)
print(popped_item) # 3
print(lst) # [1, 2]
list_find_index(lst, item)
Description: Finds the index of the first occurrence of an item in the list.
Parameters:
lst
: list - The list to search through.item
: any - The item to search for.Returns: int - The index of the first occurrence of the item, or -1 if the item is not found.
Example Usage:
from ncert_learn import list_find_index
lst = [1, 2, 3, 4]
index = list_find_index(lst, 3)
print(index) # 2
list_contains_item(lst, item)
Description: Checks if the list contains a specific item.
Parameters:
lst
: list - The list to check.item
: any - The item to check for.Returns: bool - True
if the item is found in the list, False
otherwise.
Example Usage:
from ncert_learn import list_contains_item
lst = [1, 2, 3]
contains = list_contains_item(lst, 2)
print(contains) # True
list_sort(lst, reverse=False)
Description: Sorts the list in ascending or descending order.
Parameters:
lst
: list - The list to sort.reverse
: bool, optional - Whether to sort in descending order (default is False
for ascending order).Returns: list - The sorted list.
Example Usage:
from ncert_learn import list_sort
lst = [3, 1, 2]
sorted_lst = list_sort(lst, reverse=True)
print(sorted_lst) # [3, 2, 1]
list_reverse(lst)
Description: Reverses the order of the items in the list.
Parameters:
lst
: list - The list to reverse.Returns: list - The reversed list.
Example Usage:
from ncert_learn import list_reverse
lst = [1, 2, 3]
reversed_lst = list_reverse(lst)
print(reversed_lst) # [3, 2, 1]
list_clear(lst)
Description: Clears all items from the list.
Parameters:
lst
: list - The list to be cleared.Returns: list - The cleared list (empty).
Example Usage:
from ncert_learn import list_clear
lst = [1, 2, 3]
updated_lst = list_clear(lst)
print(updated_lst) # []
list_copy(lst)
Description: Returns a shallow copy of the list.
Parameters:
lst
: list - The list to copy.Returns: list - A shallow copy of the list.
Example Usage:
from ncert_learn import list_copy
lst = [1, 2, 3]
copied_lst = list_copy(lst)
print(copied_lst) # [1, 2, 3]
list_extend(lst, other_lst)
Description: Extends the list by appending elements from another list.
Parameters:
lst
: list - The list to extend.other_lst
: list - The list whose elements will be added to lst
.Returns: list - The extended list.
Example Usage:
from ncert_learn import list_extend
lst1 = [1, 2]
lst2 = [3, 4]
extended_lst = list_extend(lst1, lst2)
print(extended_lst) # [1, 2, 3, 4]
list_count(lst, item)
Description: Counts how many times an item appears in the list.
Parameters:
lst
: list - The list to search.item
: any - The item to count.Returns: int - The number of times the item appears in the list.
Example Usage:
from ncert_learn import list_count
lst = [1, 2, 3, 2, 4]
count = list_count(lst, 2)
print(count) # 2
list_min(lst)
Description: Returns the minimum item from the list.
Parameters:
lst
: list - The list to find the minimum from.Returns: any - The minimum item in the list.
Example Usage:
from ncert_learn import list_min
lst = [1, 2, 3, 4]
min_item = list_min(lst)
print(min_item) # 1
list_max(lst)
Description: Returns the maximum item from the list.
Parameters:
lst
: list - The list to find the maximum from.Returns: any - The maximum item in the list.
Example Usage:
from ncert_learn import list_max
lst = [1, 2, 3, 4]
max_item = list_max(lst)
print(max_item) # 4
list_sum(lst)
Description: Returns the sum of all items in the list.
Parameters:
lst
: list - The list to sum.Returns: int - The sum of all items in the list.
Example Usage:
from ncert_learn import list_sum
lst = [1, 2, 3, 4]
total = list_sum(lst)
print(total) # 10
list_mean(lst)
Description: Returns the mean (average) of all items in the list.
Parameters:
lst
: list - The list to calculate the mean of.Returns: float - The mean of all items in the list, or None
if the list is empty.
Example Usage:
from ncert_learn import list_mean
lst = [1, 2, 3, 4]
mean = list_mean(lst)
print(mean) # 2.5
list_unique(lst)
Description: Returns a list of unique items from the list.
Parameters:
lst
: list - The list to extract unique items from.Returns: list - A list containing only unique items from the original list.
Example Usage:
from ncert_learn import list_unique
lst = [1, 2, 2, 3, 4]
unique_lst = list_unique(lst)
print(unique_lst) # [1, 2, 3, 4]
list_combine(lst1, lst2)
Description: Combines two lists into one.
Parameters:
lst1
: list - The first list.lst2
: list - The second list.Returns: list - The combined list.
Example Usage:
from ncert_learn import list_combine
lst1 = [1, 2]
lst2 = [3, 4]
combined_lst = list_combine(lst1, lst2)
print(combined_lst) # [1, 2, 3, 4]
list_difference(lst1, lst2)
Description: Returns the items in lst1
that are not in lst2
.
Parameters:
lst1
: list - The first list.lst2
: list - The second list.Returns: list - The items in lst1
that are not in lst2
.
Example Usage:
from ncert_learn import list_difference
lst1 = [1, 2, 3, 4]
lst2 = [3, 4, 5]
difference_lst = list_difference(lst1, lst2)
print(difference_lst) # [1, 2]
list_intersection(lst1, lst2)
Description: Returns the items that are common in both lists.
Parameters:
lst1
: list - The first list.lst2
: list - The second list.Returns: list - The items common to both lists.
Example Usage:
from ncert_learn import list_intersection
lst1 = [1, 2, 3, 4]
lst2 = [3, 4, 5]
intersection_lst = list_intersection(lst1, lst2)
print(intersection_lst) # [3, 4]
list_is_empty(lst)
Description: Checks if the list is empty.
Parameters:
lst
: list - The list to check.Returns: bool - True
if the list is empty, otherwise False
.
Example Usage:
from ncert_learn import list_is_empty
lst = []
is_empty = list_is_empty(lst)
print(is_empty) # True
mysqlconnectwithdatabase(database, host='localhost', user='root', password='', port='3306')
Description: Connects to a MySQL database with the specified database name.
Parameters:
database
: str - The name of the database to connect to.host
: str (optional) - The hostname or IP address of the MySQL server. Defaults to 'localhost'.user
: str (optional) - The MySQL username. Defaults to 'root'.password
: str (optional) - The MySQL password. Defaults to an empty string.port
: str (optional) - The port number of the MySQL server. Defaults to '3306'.Returns: bool - True if the connection was successful, False otherwise.
Example Usage:
from ncert_learn import mysqlconnectwithdatabase
success = mysqlconnectwithdatabase('my_database')
if success:
print('Connected successfully!')
else:
print('Connection failed.')
mysqlconnect(host='localhost', user='root', password='', port='3306')
Description: Connects to a MySQL server without specifying a database.
Parameters:
host
: str (optional) - The hostname or IP address of the MySQL server. Defaults to 'localhost'.user
: str (optional) - The MySQL username. Defaults to 'root'.password
: str (optional) - The MySQL password. Defaults to an empty string.port
: str (optional) - The port number of the MySQL server. Defaults to '3306'.Returns: bool - True if the connection was successful, False otherwise.
Example Usage:
from ncert_learn import mysqlconnect
success = mysqlconnect()
if success:
print('Connected to MySQL server.')
else:
print('Connection failed.')
mysqlshowdatabases()
Description: Shows all databases in the MySQL server.
Returns: tuple - A tuple of strings, where each string is a database name.
Example Usage:
from ncert_learn import mysqlshowdatabases
databases = mysqlshowdatabases()
if databases:
print(f'Databases: {databases}')
else:
print('No databases found or not connected.')
mysqlcreatedatabase(a)
Description: Creates a new database in the MySQL server with the specified name.
Parameters:
a
: str - The name of the database to be created.Returns: bool - True if the database was created successfully, False if the connection to the database is not established.
Example Usage:
from ncert_learn import mysqlcreatedatabase
success = mysqlcreatedatabase('new_database')
if success:
print('Database created successfully!')
else:
print('Failed to create database.')
mysqlshowtables()
Description: Returns a tuple of strings containing the names of all tables in the current database.
Returns: tuple - A tuple of strings, where each string is a table name.
Example Usage:
from ncert_learn import mysqlshowtables
tables = mysqlshowtables()
if tables:
print(f'Tables in the database: {tables}')
else:
print('No tables found or not connected.')
mysqlshowtablesfromdatabase(a)
Description: Returns a tuple of strings containing the names of all tables in the specified database.
Parameters:
a
: str - The name of the database.Returns: tuple - A tuple of strings, where each string is a table name, or False if the database doesn't exist or not connected.
Example Usage:
from ncert_learn import mysqlshowtablesfromdatabase
tables = mysqlshowtablesfromdatabase('my_database')
if tables:
print(f'Tables in database: {tables}')
else:
print('No tables found or invalid database.')
mysqldescribetable(a)
Description: Describes the structure of a specified table in the current database.
Parameters:
a
: str - The name of the table to describe.Returns: tuple - A tuple containing the description of the table's columns, including field name, type, nullability, key information, default values, and extra information. Returns False if the connection to the database is not established or if the table does not exist.
Example Usage:
from ncert_learn import mysqldescribetable
table_description = mysqldescribetable('my_table')
print(table_description)
mysqldescribetablefromdatabase(b, a)
Description: Describes the structure of a specified table in a specified database.
Parameters:
b
: str - The name of the database.a
: str - The name of the table to describe.Returns: tuple - A tuple containing the description of the table's columns, including field name, type, nullability, key information, default values, and extra information. Returns False if the connection to the database is not established or if the table does not exist.
Example Usage:
from ncert_learn import mysqldescribetablefromdatabase
table_description = mysqldescribetablefromdatabase('my_database', 'my_table')
print(table_description)
mysqlfetchalltable(a)
Description: Fetches all rows from a specified table in the current database.
Parameters:
a
: str - The name of the table.Returns: tuple - A tuple of tuples, where each inner tuple is a row in the table. Returns False if the connection to the database is not established or if the table does not exist.
Example Usage:
from ncert_learn import mysqlfetchalltable
table_data = mysqlfetchalltable('my_table')
print(table_data)
mysqlfetchalltablefromdatabase(b, a)
Description: Fetches all rows from a specified table in a specified database.
Parameters:
b
: str - The name of the database.a
: str - The name of the table.Returns: tuple - A tuple of tuples, where each inner tuple is a row in the table.
Example Usage:
from ncert_learn import mysqlfetchalltablefromdatabase
table_data = mysqlfetchalltablefromdatabase('my_database', 'my_table')
print(table_data)
mysqlcreatetable(database, name, d, s)
Description: Creates a new table in the specified database with the specified name and structure.
Parameters:
database
: str - The name of the database to create the table in.name
: str - The name of the table to create.d
: tuple - A tuple of strings, where each string is a field name.s
: tuple - A tuple of strings, where each string is a data type. The length of this tuple should be equal to the length of d
.Returns: bool - True if the table was created successfully, False if the connection to the database is not established or if the table already exists.
Example Usage:
from ncert_learn import mysqlcreatetable
is_created = mysqlcreatetable('my_database', 'my_table', ('field1', 'field2'), ('VARCHAR(100)', 'INT'))
print(f'Table created: {is_created}')
mysqltableinsert(database, name, s)
Description: This function is used to insert data into a table in a MySQL database.
Parameters:
database
: str - The name of the database to insert into.name
: str - The name of the table to insert into.s
: tuple - The data to insert into the table. The tuple should contain the data in the order of the columns in the table.Returns: bool - True if the data was inserted successfully, False otherwise.
Example Usage:
from ncert_learn import mysqltableinsert
success = mysqltableinsert('my_database', 'my_table', ('value1', 'value2', 3))
print(f'Data inserted: {success}')
mysqlrowcounttablefromdatabase(b, a)
Description: Returns the number of rows in a specified table from a specified database.
Parameters:
b
: str - The name of the database.a
: str - The name of the table.Returns: int - The number of rows in the table if the database and table exist. bool - False if the database or table does not exist, or if the connection is not established.
Example Usage:
from ncert_learn import mysqlrowcounttablefromdatabase
row_count = mysqlrowcounttablefromdatabase('my_database', 'my_table')
print(f'Number of rows: {row_count}')
mysqlexecutequery(s)
Description: Executes a specified SQL query.
Parameters:
s
: str - The SQL query to execute.Returns: bool - True if the query was executed successfully, False if the connection is not established, or if an error occurs.
Example Usage:
from ncert_learn import mysqlexecutequery
success = mysqlexecutequery('SELECT * FROM my_table')
print(f'Query executed successfully: {success}')
mysql_execute_advanced_mode(operation, database=None, table=None, query=None, data=None, host='localhost', user='root', password='', port='3306')
Description: Generalized function to perform various MySQL operations like connect, create DB, show DBs, fetch rows, etc.
Parameters:
operation
: str - The operation to perform. Can be 'connect', 'show_databases', 'create_database', 'show_tables', 'fetch_all', 'create_table', 'insert', 'count_rows', 'execute_query'.database
: str, optional - The database name, required for operations like 'create_table', 'insert', etc.table
: str, optional - The table name for operations like 'show_tables', 'fetch_all', 'insert', etc.query
: str, optional - The SQL query for 'execute_query' operations.data
: tuple, optional - The data to insert into a table (for 'insert' operations).host
: str, optional - The hostname or IP address of the MySQL server. Defaults to 'localhost'.user
: str, optional - The MySQL username. Defaults to 'root'.password
: str, optional - The MySQL password. Defaults to an empty string ''.port
: str, optional - The port number of the MySQL server. Defaults to '3306'.Returns: tuple or bool - Returns the result of the operation or True/False depending on success or failure.
Example Usage:
from ncert_learn import mysql_execute_advanced_mode
# Connect to the database
connection_status = mysql_execute_advanced_mode('connect', host='localhost', user='root', password='your_password')
print(f'Connection successful: {connection_status}')
# Create a new database
db_created = mysql_execute_advanced_mode('create_database', database='my_new_database')
print(f'Database created: {db_created}')
# Show all databases
databases = mysql_execute_advanced_mode('show_databases')
print(f'Available databases: {databases}')
# Create a table
table_created = mysql_execute_advanced_mode('create_table', database='my_new_database', table='my_table', data=(('id', 'INT PRIMARY KEY'), ('name', 'VARCHAR(100)')))
print(f'Table created: {table_created}')
# Insert data into the table
data_inserted = mysql_execute_advanced_mode('insert', database='my_new_database', table='my_table', data=(1, 'John Doe'))
print(f'Data inserted: {data_inserted}')
# Count rows in the table
row_count = mysql_execute_advanced_mode('count_rows', database='my_new_database', table='my_table')
print(f'Number of rows: {row_count}')
# Fetch all rows from the table
rows = mysql_execute_advanced_mode('fetch_all', database='my_new_database', table='my_table')
print(f'Fetched rows: {rows}')
# Execute a custom query
results = mysql_execute_advanced_mode('execute_query', query='SELECT * FROM my_table')
print(f'Query results: {results}')
bubblesort(a)
Description: Bubblesort Algorithm for sorting a list of numbers in ascending order. It takes a list of numbers as an argument and returns a sorted list in ascending order. If the argument is not a list, it returns False. If the list is empty, it returns an empty list.
Parameters:
a
: list - The list of numbers to be sorted.Returns: list - The sorted list in ascending order.
Example Usage:
from ncert_learn import bubblesort
sorted_list = bubblesort([5, 2, 9, 1, 5, 6])
print(f'Sorted list: {sorted_list}')
insertionsort(a)
Description: Insertion Sort Algorithm for sorting a list of numbers in ascending order. This function sorts a list of numbers using the insertion sort algorithm. If the input is not a list, it returns False. If the list is empty, it returns an empty list.
Parameters:
a
: list - The list of numbers to be sorted.Returns: list - The sorted list in ascending order, or False if the input is not a list.
Example Usage:
from ncert_learn import insertionsort
sorted_list = insertionsort([5, 2, 9, 1, 5, 6])
print(f'Sorted list: {sorted_list}')
createstackdict()
Description: Creates a new empty stack represented as a dictionary.
Returns: dict - An empty dictionary.
Example Usage:
from ncert_learn import createstackdict
stack = createstackdict()
print(f'Stack created: {stack}')
clearstackdict(a)
Description: Clears the stack represented as a dictionary. This function does not return any value.
Parameters:
a
: dict - The stack represented as a dictionary to be cleared.Returns: None
Example Usage:
from ncert_learn import clearstackdict
stack = {'a': 1, 'b': 2}
clearstackdict(stack)
print(f'Stack after clearing: {stack}')
pushstackdict(a, b)
Description: Pushes a dictionary onto the stack represented as another dictionary. This function does not return a value.
Parameters:
a
: dict - The stack represented as a dictionary.b
: dict - The dictionary to be pushed onto the stack.Returns: None
Example Usage:
from ncert_learn import pushstackdict, createstackdict
stack = createstackdict()
pushstackdict(stack, {'a': 1})
print(stack) # Output: {'a': 1}
pushstackdict(stack, {'b': 2})
print(stack) # Output: {'a': 1, 'b': 2}
popstackdict(a)
Description: Removes and returns the last inserted key-value pair from the stack represented as a dictionary. If the stack is empty, it returns -1.
Parameters:
a
: dict - The stack represented as a dictionary.Returns: dict or int - The modified dictionary or -1 if the stack is empty.
Example Usage:
from ncert_learn import popstackdict
stack = {'a': 1, 'b': 2}
modified_stack = popstackdict(stack)
print(modified_stack) # Output: {'a': 1}
empty_stack_result = popstackdict({})
print(empty_stack_result) # Output: -1
peekstackdict(a)
Description: Returns the value of the last inserted key in the stack represented as a dictionary without removing it. If the stack is empty, it returns -1.
Parameters:
a
: dict - The stack represented as a dictionary.Returns: any or int - The value of the last inserted key if the stack is not empty, otherwise -1.
Example Usage:
from ncert_learn import peekstackdict
stack = {'a': 1, 'b': 2}
last_value = peekstackdict(stack)
print(last_value) # Output: 2
empty_peek = peekstackdict({})
print(empty_peek) # Output: -1
displaymodestackdict(a)
Description: Returns a list of the items in the stack represented as a dictionary where each item is a tuple of the key-value pair. The list is ordered with the most recently inserted key-value pair at the end of the list. If the stack is empty, it returns an empty list.
Parameters:
a
: dict - The stack represented as a dictionary.Returns: list - A list of tuples representing the key-value pairs in the stack.
Example Usage:
from ncert_learn import displaymodestackdict
stack = {'a': 1, 'b': 2}
items = displaymodestackdict(stack)
print(items) # Output: [('a', 1), ('b', 2)]
createstacklst()
Description: Creates an empty stack implemented as a list.
Returns: list - An empty list to be used as a stack.
Example Usage:
from ncert_learn import createstacklst
stack = createstacklst()
print(stack) # Output: []
clearstacklst(a)
Description: Clears the stack implemented as a list. This function does not return any value.
Parameters:
a
: list - The stack implemented as a list to be cleared.Returns: None
Example Usage:
from ncert_learn import clearstacklst
stack = [1, 2, 3]
clearstacklst(stack)
print(stack) # Output: []
pushstacklst(a, b)
Description: Pushes an item onto the stack implemented as a list.
Parameters:
a
: list - The stack implemented as a list.b
: object - The item to be pushed onto the stack.Returns: list - The modified stack implemented as a list.
Example Usage:
from ncert_learn import pushstacklst
stack = []
pushstacklst(stack, 1)
print(stack) # Output: [1]
pushstacklst(stack, 2)
print(stack) # Output: [1, 2]
popstacklst(a)
Description: Pops an item from the stack implemented as a list. If the stack is empty, -1 is returned. Otherwise, the popped item is returned and the stack is modified.
Parameters:
a
: list - The stack implemented as a list.Returns: object - The popped item if the stack is not empty, -1 otherwise.
Example Usage:
from ncert_learn import popstacklst
stack = [1, 2, 3]
popped_item = popstacklst(stack)
print(popped_item) # Output: 3
print(stack) # Output: [1, 2]
empty_pop = popstacklst([])
print(empty_pop) # Output: -1
peekstacklst(a)
Description: Returns the top element from the stack implemented as a list without removing it. If the stack is empty, -1 is returned. Otherwise, the top element is returned.
Parameters:
a
: list - The stack implemented as a list.Returns: object - The top element if the stack is not empty, -1 otherwise.
Example Usage:
from ncert_learn import peekstacklst
stack = [1, 2, 3]
top_item = peekstacklst(stack)
print(top_item) # Output: 3
empty_peek = peekstacklst([])
print(empty_peek) # Output: -1
displaymodestacklst(a)
Description: Returns a modified version of the stack implemented as a list by reversing the order of its elements.
Parameters:
a
: list - The stack implemented as a list to be modified.Returns: list - The modified stack implemented as a list with the order of its elements reversed.
Example Usage:
from ncert_learn import displaymodestacklst
stack = [1, 2, 3]
reversed_stack = displaymodestacklst(stack)
print(reversed_stack) # Output: [3, 2, 1]
str_reverse(s)
Description: Reverses the input string.
Parameters:
s
: str - The string to be reversed.Returns: str - The reversed string.
Example Usage:
from ncert_learn import str_reverse
reversed_str = str_reverse('hello')
print(f'Reversed string: {reversed_str}')
str_to_upper(s)
Description: Converts the input string to uppercase.
Parameters:
s
: str - The string to be converted to uppercase.Returns: str - The uppercase version of the input string.
Example Usage:
from ncert_learn import str_to_upper
uppercase_str = str_to_upper('hello')
print(f'Uppercase string: {uppercase_str}')
str_to_lower(s)
Description: Converts the input string to lowercase.
Parameters:
s
: str - The string to be converted to lowercase.Returns: str - The lowercase version of the input string.
Example Usage:
from ncert_learn import str_to_lower
lowercase_str = str_to_lower('HELLO')
print(f'Lowercase string: {lowercase_str}')
str_is_palindrome(s)
Description: Checks if the input string is a palindrome.
Parameters:
s
: str - The string to be checked.Returns: bool - True
if the string is a palindrome, False
otherwise.
Example Usage:
from ncert_learn import str_is_palindrome
is_palindrome = str_is_palindrome('madam')
print(f'Is palindrome: {is_palindrome}')
str_count_occurrences(s, substring)
Description: Counts occurrences of a substring in the input string.
Parameters:
s
: str - The string to be searched.substring
: str - The substring to count in the string.Returns: int - The number of times the substring appears in the string.
Example Usage:
from ncert_learn import str_count_occurrences
occurrences = str_count_occurrences('hello world', 'o')
print(f'Occurrences of "o": {occurrences}')
str_is_alpha(s)
Description: Checks if the string contains only alphabetic characters.
Parameters:
s
: str - The string to be checked.Returns: bool - True
if the string contains only alphabetic characters, False
otherwise.
Example Usage:
from ncert_learn import str_is_alpha
is_alpha = str_is_alpha('hello')
print(f'Is alphabetic: {is_alpha}')
str_is_digit(s)
Description: Checks if the string contains only digits.
Parameters:
s
: str - The string to be checked.Returns: bool - True
if the string contains only digits, False
otherwise.
Example Usage:
from ncert_learn import str_is_digit
is_digit = str_is_digit('12345')
print(f'Is digit: {is_digit}')
str_find_substring(s, substring)
Description: Finds the first occurrence of a substring in the input string.
Parameters:
s
: str - The string to be searched.substring
: str - The substring to search for.Returns: int - The index of the first occurrence of the substring, or -1
if not found.
Example Usage:
from ncert_learn import str_find_substring
index = str_find_substring('hello world', 'world')
print(f'Index of "world": {index}')
str_replace_substring(s, old, new)
Description: Replaces occurrences of a substring with another substring.
Parameters:
s
: str - The string to be modified.old
: str - The substring to replace.new
: str - The substring to replace with.Returns: str - The modified string with replacements made.
Example Usage:
from ncert_learn import str_replace_substring
modified_str = str_replace_substring('hello world', 'world', 'everyone')
print(f'Modified string: {modified_str}')
str_split_words(s)
Description: Splits the string into words.
Parameters:
s
: str - The string to be split into words.Returns: list - A list of words in the string.
Example Usage:
from ncert_learn import str_split_words
words = str_split_words('hello world')
print(f'Splitted words: {words}')
str_strip_spaces(s)
Description: Removes leading and trailing spaces from the string.
Parameters:
s
: str - The string to be stripped.Returns: str - The string without leading or trailing spaces.
Example Usage:
from ncert_learn import str_strip_spaces
stripped_str = str_strip_spaces(' hello world ')
print(f'Stripped string: "{stripped_str}"')
str_startswith(s, prefix)
Description: Checks if the string starts with a specific prefix.
Parameters:
s
: str - The string to be checked.prefix
: str - The prefix to check for.Returns: bool - True
if the string starts with the prefix, False
otherwise.
Example Usage:
from ncert_learn import str_startswith
starts_with = str_startswith('hello world', 'hello')
print(f'Starts with "hello": {starts_with}')
str_endswith(s, suffix)
Description: Checks if the string ends with a specific suffix.
Parameters:
s
: str - The string to be checked.suffix
: str - The suffix to check for.Returns: bool - True
if the string ends with the suffix, False
otherwise.
Example Usage:
from ncert_learn import str_endswith
ends_with = str_endswith('hello world', 'world')
print(f'Ends with "world": {ends_with}')
str_isalnum(s)
Description: Checks if the string contains only alphanumeric characters.
Parameters:
s
: str - The string to be checked.Returns: bool - True
if the string contains only alphanumeric characters, False
otherwise.
Example Usage:
from ncert_learn import str_isalnum
is_alnum = str_isalnum('hello123')
print(f'Is alphanumeric: {is_alnum}')
str_title_case(s)
Description: Converts the string to title case.
Parameters:
s
: str - The string to be converted to title case.Returns: str - The string in title case.
Example Usage:
from ncert_learn import str_title_case
title_case_str = str_title_case('hello world')
print(f'Title case: {title_case_str}')
str_find_substring(s, substring)
Description: Finds the first occurrence of a substring in the string.
Parameters:
s
: str - The string to search within.substring
: str - The substring to find.Returns: int - The index of the first occurrence of the substring, or -1
if not found.
Example Usage:
from ncert_learn import str_find_substring
index = str_find_substring('hello world', 'world')
print(f'Index of "world": {index}')
str_concat(s1, s2)
Description: Concatenates two strings.
Parameters:
s1
: str - The first string.s2
: str - The second string.Returns: str - The concatenated string.
Example Usage:
from ncert_learn import str_concat
concatenated_str = str_concat('hello', ' world')
print(f'Concatenated string: {concatenated_str}')
str_join(separator, iterable)
Description: Joins the elements of an iterable into a single string with a separator.
Parameters:
separator
: str - The separator between elements.iterable
: iterable - The iterable containing elements to be joined.Returns: str - The joined string.
Example Usage:
from ncert_learn import str_join
joined_str = str_join('-', ['hello', 'world'])
print(f'Joined string: {joined_str}')
istextfile(file_path)
Description: Checks if a file is a text file by attempting to read its first 1024 bytes.
Parameters:
file_path
: str - The path to the file to check.Returns: bool - True
if the file is a text file, False
otherwise.
Example Usage:
from ncert_learn import istextfile
is_text = istextfile('sample.txt')
print(f'Is text file: {is_text}')
copytextfromonetoanother(a, b)
Description: Copies the text from the file given by path a
to the file given by path b
.
Parameters:
a
: str - The path of the file to copy from.b
: str - The path of the file to copy to.Returns: bool - True
if the copy operation is successful, False
otherwise.
Example Usage:
from ncert_learn import copytextfromonetoanother
success = copytextfromonetoanother('source.txt', 'destination.txt')
print(f'Copy successful: {success}')
opentextfile(a)
Description: Opens the text file given by path a
in the default text editor.
Parameters:
a
: str - The path of the file to open.Returns: bool - True
if the file is opened successfully, False
otherwise.
Example Usage:
from ncert_learn import opentextfile
opened = opentextfile('sample.txt')
print(f'File opened: {opened}')
addlinetotextfile(a)
Description: Appends a line of text to the file opened by the opentextfile()
function.
Parameters:
a
: str - The line of text to append.Returns: bool - True
if the line is appended successfully, False
otherwise.
Example Usage:
from ncert_learn import addlinetotextfile
success = addlinetotextfile('This is a new line.')
print(f'Line appended: {success}')
readtextfile(a)
Description: Reads the contents of the file opened by the opentextfile()
function.
Parameters:
a
: str - Ignored.Returns: str - The contents of the file as a string.
Example Usage:
from ncert_learn import readtextfile
file_contents = readtextfile('')
print(f'File contents: {file_contents}')
cleartextfile()
Description: Clears the contents of the file opened by the opentextfile()
function.
Parameters:
None
Returns: None
Example Usage:
from ncert_learn import cleartextfile
cleartextfile()
print('File content cleared.')
readspecificlinetextfile(line_number)
Description: Reads a specific line from the file opened by the opentextfile()
function.
Parameters:
line_number
: int - The line number to read from the file (1-based index).Returns: str - The content of the specified line, or bool - False
if the file is not found or the line number is out of range.
Example Usage:
from ncert_learn import readspecificlinetextfile
line_content = readspecificlinetextfile(2)
print(f'Second line: {line_content}')
overwritetextfile(new_content)
Description: Overwrites the contents of the currently opened text file with new content.
Parameters:
new_content
: str - The new content to write to the file.Returns: bool - True
if the operation is successful, False
otherwise.
Example Usage:
from ncert_learn import overwritetextfile
success = overwritetextfile('New content for the file.')
print(f'File overwritten: {success}')
text_file_operations_advanced_mode(folder_path, operation, file_name=None, new_name=None, data=None)
Description: Performs various text file operations in a specified folder. Operations include creating, writing, appending, reading, clearing, deleting, renaming, and listing files.
Parameters:
folder_path
: str - Path to the folder where operations will be performed.operation
: str - The operation to perform (e.g., 'create', 'write', 'append', 'read', 'clear', 'delete', 'rename', 'list_files', 'overwrite').file_name
: str - The file name for the operation (optional, required for most operations).new_name
: str - New name for the file (used in 'rename', optional).data
: str - Text data for 'write', 'append', or 'overwrite' operations (optional).Returns: bool, str, or list - Depending on the operation:
Example Usage:
from ncert_learn import text_file_operations_advanced_mode
# Create a file
text_file_operations_advanced_mode('folder_path', 'create', 'file.txt')
# Write to a file
text_file_operations_advanced_mode('folder_path', 'write', 'file.txt', data='Hello, World!')
# Read from a file
content = text_file_operations_advanced_mode('folder_path', 'read', 'file.txt')
print(content)
text_file_operations_advanced_mode(folder_path, operation='append', file_name=None, new_name=None, data=None)
Description: Appends a line of text to the file in advanced mode. This function allows for various file operations based on the specified operation type.
Parameters:
folder_path
: str - Path to the folder where the operations will be performed.operation
: str - The operation to perform (e.g., 'create', 'write', 'append', 'read', 'clear', 'delete', 'rename', 'list_files', 'overwrite').file_name
: str - The file name for the operation (optional, required for most operations).new_name
: str - New name for the file (used in 'rename', optional).data
: str - Text data for 'write', 'append', or 'overwrite' operations (optional).Returns: bool - Returns True on success or False on failure.
Example Usage:
from ncert_learn import text_file_operations_advanced_mode
# Append a line of text to a file
text_file_operations_advanced_mode('folder_path', 'append', 'file.txt', data='New line of text.')
text_file_operations_advanced_mode(folder_path, operation='delete', file_name=None)
Description: Deletes the specified file from the folder in advanced mode.
Parameters:
folder_path
: str - Path to the folder where the file is located.operation
: str - The operation to perform, in this case 'delete'.file_name
: str - The name of the file to delete.Returns: bool - Returns True if the file was deleted successfully, False on failure.
Example Usage:
from ncert_learn import text_file_operations_advanced_mode
# Delete a file
text_file_operations_advanced_mode('folder_path', 'delete', 'file_to_delete.txt')