Python Lecture 1-Fundamental-Algorithms
Python Lecture 1-Fundamental-Algorithms
Swapping
• Problem
Given two variables, a and b exchange the values
assigned to them
Now,
• Problem
Given a set of n students who have marks in the
range (0,100) in a course. The pass marks in the
course are 50. Find how many students have
passed the course.
• Problem
Given a set of n students who have marks in the
range (0,100) in a course. The pass marks in the
course are 50. Find how many students have
passed the course.
• Problem
Given a set of n numbers find the sum of these
numbers.
• Problem
Given a number n, compute n factorial (n!) where
n>=0
We know n!=1x2x3x…x(n-1)xn
0!=1
1!=1
2!=1x2
3!=1x2x3
n! can be computed as nx(n-1)!
Factorial
input n
factor=1
for i=1 to n do
factor = i*factor
output factor
Sine function as series
• Problem
Evaluate sin(x) as a series expansion i.e, upto n
terms
Sine function as series
• Problem
Evaluate sin(x) as a series expansion i.e
i.e, upto n
terms
• Problem
Generate and print first n terms of Fibonacci
sequence, which looks like
0, 1, 1, 2, 3, 5, 8, 13 ….