Exercise 1 – Basics
[Link] instructions in Interactive interpreter and a Python Script
In Python, there are two options/methods for running code:
Interactive mode
Script mode
Interactive Mode
Example :
Script Mode
You Write your code in a text file then save it with a .py extension which stand for
“Python”.
Example :
Output : -
[Link] a program to purposefully raise Indentation Error and Correct it
Example : Python Indentation Error
Example : Now Fixing the indentation Error in the example of python
programs
Output : -
Exercise 2 - Operations
[Link] a program to compute distance between two points taking input
from the user (Pythagorean Theorem)
We will use the distance formula derived from Pythagorean theorem. The
formula for distance between two point (x1, y1) and (x2, y2) is
Distance =
Example : -
Output : -
[Link] a program [Link] that takes 2 numbers as command line
arguments and prints its sum.
Save a program [Link]
Output : -
Exercise - 3 Control Flow
1. Write a Program for checking whether the given number is a
even number or not.
Output : -
# Number is 4 and it is even number
# Number is 5 and it is not even number
[Link] a for loop, write a program that prints out the decimal equivalents of
1/2, 1/3, 1/4, . . . ,1/10
Output : -
1/2=0.5
1/3= 0.3333333333333
…
…..
1/10=
0.1
2. Write a program using a for loop that loops over a sequence.
Output : -
3. Write a program using a while loop that asks the user for a
number, and prints a countdown from that number to zero.
Output : -
Exercise 4 - Control Flow –
Continued
1. Find the sum of all the primes below two million. Adding the previous
two terms, each new term in the Fibonacci sequence is generated. By
starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55,
89, ...
# The sum of all the primes below two million
Output : -
# Fibonacci sequence
Output : -
2. By considering the terms in the Fibonacci sequence whose values
do not exceed four million, find the sum of the even-valued terms.
Output :-
[Link] search and Binary search
# Linear Search
Output : -
#Binary Search
Output : -
4. Selection sort, Insertion sort
# Selection sort
Output : -
# Insertion Sort
Output : -
Exercise - 5 – DS
1. Writea program to count the numbers of characters in the string
and store them in a dictionary data structure
Output : -
2:Write a program to use split and join methods in the string
and trace a birthday with a dictionary data structure.
output: