0% found this document useful (0 votes)
3 views

algorithm

The document outlines a series of programming tasks that involve user input, data manipulation, and calculations such as mean, median, mode, quartiles, and standard deviation. It also covers variable declarations, operator demonstrations, function definitions, and file operations. Each task is structured with a start and end point, guiding the user through the coding process.

Uploaded by

Viyan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

algorithm

The document outlines a series of programming tasks that involve user input, data manipulation, and calculations such as mean, median, mode, quartiles, and standard deviation. It also covers variable declarations, operator demonstrations, function definitions, and file operations. Each task is structured with a start and end point, guiding the user through the coding process.

Uploaded by

Viyan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1: Start.

Initialize an empty list.


Take input from the user repeatedly to populate the list. Allow users to stop input
using a specific keyword (e.g., "done").
Calculate:
Mean: Sum of all numbers divided by their count.
Median: Middle element in the sorted list (or average of two middle elements
if the list length is even).
Mode: Most frequently occurring element(s) in the list.
Sort the list in ascending order and display it.
Use continue, pass, and break within an example loop:
Use continue to skip over numbers less than zero.
Use pass as a placeholder.
Use break to exit the loop when a specific condition is met.
Display the results (mean, median, mode, and sorted list).
End.

----------------------------------------------------------------------------

Q2: Start.
Initialize an empty list.
Take input from the user to populate the list. Allow the user to stop input using a
specific keyword (e.g., "done").
Calculate:
Range: Difference between the maximum and minimum values.
Average Deviation: Average of the absolute differences between each value and
the mean.
Absolute Deviations: Absolute differences between each value and the mean.
Squared Deviations: Squared differences between each value and the mean.
Standard Deviation: Square root of the variance (mean of squared deviations).
Display the results.
End.

---------------------------------------------------------------------------------

Q3:Start.

Initialize an empty list.


Take input from the user to populate the list. Allow the user to stop input using a
specific keyword (e.g., "done").
Sort the list.
Calculate:
Q1 (1st Quartile): Median of the lower half of the sorted list.
Q3 (3rd Quartile): Median of the upper half of the sorted list.
IQR: Difference between Q3 and Q1.
Outlier thresholds: Values < (Q1 - 1.5 × IQR) or > (Q3 + 1.5 × IQR).
Identify outliers in the list based on the thresholds.
Display the results.
End.

-----------------------------------------------------------------------------------
--
Q4:

Start.
Declare variables for each data type: integer, float, string, boolean, list, tuple,
set, and dictionary.
Assign sample values to each variable.
For each variable:
Print its value.
Print its data type using type().
End.

-----------------------------------------------------------------------------------
Q5:
Start.
Declare variables to perform operations.
Demonstrate arithmetic operators:
Addition, subtraction, multiplication, division, modulus, exponentiation, and
floor division.
Demonstrate comparison operators:
Equality, inequality, greater than, less than, etc.
Demonstrate logical operators:
AND, OR, NOT.
Showcase operator precedence by combining multiple operators in an expression.
Print the results of all operations.
End.

-----------------------------------------------------------------------------------
--
Q6:
Start.
Declare example variables of different types (integer, float, string, boolean,
list, tuple, etc.).
Perform the following conversions:
Integer ↔ String
String ↔ Float
String ↔ Boolean
List ↔ Tuple
List ↔ Set
Print the results of each conversion.
End.
-----------------------------------------------------------------------------
Q7.
Start.
Prompt the user to enter their name.
Prompt the user to enter their age.
Print a greeting message using the provided name and age.
End.

-----------------------------------------------------------------------------
Q8:
Start.
Write single-line comments to explain specific parts of the code.
Write multi-line comments for a detailed explanation of the program or larger
sections of code.
Execute the program to validate its functionality.
End.

-----------------------------------------------------------------------------
Q9:

Start.
Import the built-in math module.
Prompt the user to input a number.
Calculate the square root of the number using the math.sqrt() function.
Print the square root result.
Print the value of π using math.pi.
End.

-----------------------------------------------------------------------------
Q10:

Start.
Demonstrate if-else:
Check if a number is positive, negative, or zero.
Demonstrate a for loop:
Print the elements of a list.
Demonstrate a while loop:
Count down from a given number to 1.
End.

-----------------------------------------------------------------------------
Q11:

Start.
Define a function named greet_user that:
Accepts a name as a parameter.
Prints a greeting message using the provided name.
Prompt the user to enter their name.
Call the greet_user function with the input name.
End.

-----------------------------------------------------------------------------
Q12:
Start.
Declare example variables and values for demonstration.
Demonstrate the use of:
abs(): To compute the absolute value of a number.
max(): To find the maximum value in a list.
min(): To find the minimum value in a list.
len(): To determine the length of a list.
round(): To round a float to the nearest integer (or to specified decimal
places).
Print the results of each function.
End.

---------------------------------------------------------------------------------

Q13:

Start.
Import the built-in random module.
Use the randint() function from the random module to generate a random integer in
the range 1 to 100.
Print the generated random number.
End.

---------------------------------------------------------------------------
Q14:

Start.
Create and open a file in write mode (w).
Write some data to the file.
Close the file.
Open the file in read mode (r) and read its content.
Open the file in append mode (a) and add new data.
Open the file again in read mode and read it line by line.
Close the file after each operation.
End.

------------------------------------------------------------------------------
Q15:

Start.
Import the necessary libraries: numpy, matplotlib, and sklearn.
Generate a dataset or load an existing one.
Use the K-Means algorithm to cluster the data into k groups.
Extract cluster centroids and labels from the K-Means model.
Visualize the clustered data points and their corresponding centroids on a scatter
plot.
End.

You might also like