coth

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 8

What is an algorithm?

Write any three characteristics of


an algorithm.
The step-by-step procedure to solve any logical and
mathematical problem is called an Algorithm. Three
characteristics of an algorithm are:
1. Input—An algorithm accepts an input.
2. Generality—An algorithm works in a set of inputs.
3. Definiteness—Each instruction should be written in a
simple and precise manner so that everyone can
understand it.

What are the characteristics of a good algorithm?


Following are the characteristics of a good algorithm:
a. It receives an input.
b. It works on a set of inputs.
c. The steps must be precisely defined.
d. The result of each step should depend on the results of
previous steps. e. It stops after a finite number of
instructions.
f. It produces the desired output.

Research
Supercomputers.
Mainframe computers.
Minicomputers.
Personal computers (PCs) or microcomputers

What are the advantages of Algorithm?


It is a step-wise representation of a solution to a given
problem, which makes it easy to understand.
An algorithm uses a definite procedure.
It is not dependent on any programming language, so it is
easy to understand for anyone even without
programming knowledge.
Every step in an algorithm has its own logical sequence so
it is easy to debug.
Python Data Types are used to define the type of a
variable. It defines what type of data we are going to
store in a variable. The data stored in memory can be of
many types.

For example, a person's age is stored as a numeric value


and his or her address is stored as alphanumeric
characters.

integer (int) e.g. 10, -10


2. float (float) e.g. 10.10, 7582.8509
3. Boolean (bool) e.g (true and flase)
4. String (str) eg. (‘Rose’, ‘white’)
5. Character (char) eg. (‘a’,’x’)

# to display the numbers from 10 to 0 using for loop.


#i = 10
#while (i>=10):
for i in range (10, -1, -1):
print(i)
# i-=1

S = int(input("Enter the starting number: "))


E = int(input("Enter the ending number: "))
for S in range(S,E+1,1):
print(S)
for S in range(S, E-1, -1):
print(S)

starting_point = int(input("Enter the starting number: "))


ending_point = int(input("Enter the ending number: "))

while starting_point <= ending_point:


print(starting_point)
starting_point += 1
While loop
1. sum = 0

2. counter = 0

3.

4. while counter <= 10:

5. sum += counter

6. counter += 1

7.

8. print("The sum using while loop is:", sum)

For loop
9. sum = 0

10.

11. for number in range(11): # Range includes the upper bound (10)

12. sum += number

13.

14. print("The sum using for loop is:", sum)

#WAPP, to calculate the sum of all numbers from 0 to 10 using while loop
x = int(input("enter the firat range: "))
y = int(input("enter the last range: "))
sum = 0
for x in range (x,y+1):
sum+=x
print(sum)

print("Squares of numbers from 0 to 10 using while loop:")


i = 0
while i <= 10:
print(f"The square of {i} is {i * i}")
i += 1
print()

print("Squares of numbers from 0 to 10 using for loop:")


for i in range(11):
print(f"The square of {i} is {i * i}")

# To finding the Prime numbers from one range to another range........

start = int(input("Enter the starting point : "))

limit = int(input("Enter the end limit point: "))


for num in range (start, limit+1):

if (num > 1):

for i in range (2, num):

if (num%i==0):

print(num,"is not a prime.")

break

else:

print(num,"is a prime number.")

Definition

Python len() is a built-in function that returns the number of elements


(length) in an iterator/object passed to the function.

The Python len() function is used to return a numeric value that denotes the
length of the given list, tuple, string, array, dictionary, etc.

num = int(input("Enter the number: "))


num1 = str(num)
num_digit = {
"1": "One",
"2": "Two",
"3": "Three",
"4": "Four",
"5": "Five",
"6": "six",
"7": "Sevem",
"8": "Eight",
"9": "Nine",
"0": "Zero",
}
for i in num1:
print("\nThe converted number is : ", num_digit[i])

sum = 0
Choice = "Y"
while (Choice.upper() == "Y"):
num = int(input("Enter any number : "))
sum += num
Choice = input("Do you want to contiue? (Y/N): ")
print("The Total is : ", sum)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy