0% found this document useful (0 votes)
15 views31 pages

Install Anaconda: Step-by-Step Guide

The document provides a comprehensive guide on installing Anaconda, running the installer, verifying the installation, and updating it. It includes various coding examples in Python, covering topics such as input/output statements, conditional statements, loops, set operations, tuples, lists, dictionaries, and string manipulation. Each section contains code snippets and expected outputs to aid understanding and execution.

Uploaded by

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

Install Anaconda: Step-by-Step Guide

The document provides a comprehensive guide on installing Anaconda, running the installer, verifying the installation, and updating it. It includes various coding examples in Python, covering topics such as input/output statements, conditional statements, loops, set operations, tuples, lists, dictionaries, and string manipulation. Each section contains code snippets and expected outputs to aid understanding and execution.

Uploaded by

jhenkargowdabh2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Installation of Anaconda (Python Distribution)

Step 1: Download Anaconda


1. Go to the official website: [Link]
2. Click Download for your operating system (Windows, Mac, Linux).
3. Choose the Python 3.x version (latest recommended).

Step 2: Run the Installer


1. Open the downloaded installer file.
2. Click Next → Read and accept the License Agreement → Click Next.
3. Choose Just Me (recommended) → Click Next.
4. Select installation location (default is fine) → Click Next.
5. Check the box “Add Anaconda to my PATH environment variable” (optional, but
recommended).
6. Click Install. Wait for the installation to complete.

Step 3: Verify Installation


1. Open Anaconda Navigator (GUI) or Anaconda Prompt (command line).
2. Type in Anaconda Prompt:
Conda --version
Output example:
conda 23.3.1
3. Open Python by typing:
python
You should see the Python version installed via Anaconda.
Step 4: Update Anaconda (Optional but Recommended)
Conda update Conda
Conda update anaconda

Step 5: Launch Anaconda Navigator


• Open Anaconda Navigator from Start Menu (Windows) or Applications (Mac).
• From here you can launch Jupyter Notebook, Spyder IDE, or VS Code.
[Link], execute and debug programs
a) Use I/O statements.
b) Evaluate expressions and displays formatted output.
c) Evaluate expressions to examine the operator precedence.

a) Use I/O statements.


i=6
f=3.6
c=4+3j
b=True
s="Welcome to python lab"
print("the value of i:”, i,"\nits type :”, type(i))
print("the value of i:”, f,"\nits type :”, type(f))
print("the value of i:",c,"\nits type :", type(c))
print("the value of i:",b,"\nits type :”, type(b))
print("the value of i:",s,"\nits type :",type(s))

OUTPUT:
the value of i: 6
its type is: <class 'int'>
the value of i: 3.6
its type: <class 'float'>
the value of i: (4+3j)
its type: <class 'complex'>
the value of i: True
its type: <class 'bool'>
the value of i: Welcome to python lab
its type: <class 'str'>
b) Evaluate expressions and displays formatted output.
import time
import datetime OUTPUT:
x=[Link] () Fri Oct 24 [Link] 2025
print([Link]("%c"))

c) Evaluate expressions to examine the operator precedence.

a=int(input("Enter the first number:"))


OUTPUT:
b=int(input("Enter the first number:"))
Enter the first number:9
print()
Enter the first number:4
print("Addition (a+b) :",a+b)
Addition (a+b) : 13
print("Subtraction (a-b) :",a-b)
Subtraction (a-b) : 5
print("Multiplication (a*b):",a*b)
Multiplication (a*b): 36
print("Division (a/b) :",a/b)
Division (a/b) : 2.25
print("Division (a//b) :",a//b)
Division (a//b) :2
print("Modulus (a%b) :",a%b)
Modulus (a%b) :1
print("Power(a**b) :",a**b)
Power(a**b) : 6561
3. Identify and Code, execute and debug programs using conditional
statements (type code to build a grading system based on marks).

marks=int(input("Enter the marks:"))


if marks>=85 and marks<=100:
print("congrats! you scored grade A")
elif marks>=60 and marks<=85:
print("you scored grade B+")
elif marks>=40 and marks<=60:
print("you scored grade B")
elif marks>=30 and marks<=40:
print("you scored grade C ")
else:
print("sorry your fail")

OUTPUT:
case1:
Enter the marks:89
congrats! you scored grade A
case2:
Enter the marks:75
you scored grade B+
case3:
Enter the marks:24
sorry your fail
4. Code, execute and debug programs.
A) using loops.
adj=["red","big","tasty"]
fruity=["apple","banana","cheery"]
for x in adj:
for y in fruity:
print(x,y)

OUTPUT:
Red Apple
Red Banana
Red Cheery
Big Apple
Big Banana
Big Cheery
Tasty Apple
Tasty Banana
Tasty Cheery
b) Code, execute and debug programs using loops and conditional
statements.
start=25
end=50
print("Prime numbers between”, start, "and", end, "are:")
for num in range(start,end+1):
if num>1:
for i in range (2,num):
if(num%i==0):
break
else:
print(num)

OUTPUT:
Prime numbers between 25 and 50 are:
29
31
37
41
43
47
5 a). Code, execute and debug programs to perform following
▪ set operations
▪ set comprehension
a) set operations
E= {0,2,4,6,8}
N= {1,2,3,4,5}
print("union of E&N is:”, E|N)
print("Intersection of E&N is:”, E&N)
print("Difference of E&N is:”, E-N)
print(“symmetric difference of E&N is:”, E^N)

output:
union of E&N is: {0, 1, 2, 3, 4, 5, 6, 8}
Intersection of E&N is: {2, 4}
Difference of E&N is: {0, 8, 6}
symmetric Difference of E&N is: {0, 1, 3, 5, 6, 8}

b) set comprehension

Days1 = {"Monday", "Tuesday", "Wednesday", "Thursday"}


Days2 = {"Monday", "Tuesday"}
Days3 = {"Monday", "Tuesday", "Friday"}
print("Days1 == Days2:", Days1 == Days2)
print("Days1 == Days3:", Days1 == Days3)
print("Days1 != Days2:", Days1 != Days2)
print("Days1 != Days3:", Days1 != Days3)

OUTPUT:

Days1 == Days2: False


Days1 == Days3: False
Days1 != Days2: True
Days1 != Days3: True
5 b). Code, execute and debug programs to perform following

▪ basic operations on tuples

tuple1 = ('Cat', 'Rat', 'Dog')


tuple2 = ('Cat', 'Rat', 'Dog')
tuple3 = ('Cat', 'Rat', 'dog')
tuple4 = ('Cat', 'Rat', 'DOg')
print("Tuple1 == Tuple2:", tuple1 == tuple2)
print("Tuple2 == Tuple3:", tuple2 == tuple3)
print("Tuple3 == Tuple4:", tuple3 == tuple4)
print("Tuple4 == Tuple1:", tuple4 == tuple1)

output:
Tuple1 == Tuple2: True
Tuple2 == Tuple3: False
Tuple3 == Tuple4: False
Tuple4 == Tuple1: False
▪ tuple indexing and slicing

tuplex = tuple("computer science")


print("Tuple:", tuplex)
index_p = [Link]("p")
print("Index value of 'p' =", index_p)
index_e = [Link]("e")
print("Index value of 'e' =", index_e)
print("First 5 elements:", tuplex[:5])
print("Last 5 elements:", tuplex[-5:])

OUTPUT:

Tuple: ('c', 'o', 'm', 'p', 'u', 't', 'e', 'r', ' ', 's', 'c', 'i', 'e', 'n', 'c', 'e')
Index value of 'p' = 3
Index value of 'e' = 6
First 5 elements: ('c', 'o', 'm', 'p', 'u')
Last 5 elements: ('i', 'e', 'n', 'c', 'e')
6. Write code snippet to perform following on List
a). basic operations on List
list_one = [10, 20, 30, 40]
list_two = [30, 40, 50]
print("List one <List two:", list_one < list_two)
print("List one > List two:", list_one >= list_two)
print("List one < =List two:", list_one <=list_two)
print("List one >=List two:", list_one <=list_two)
print("List one = =List two:", list_one ==list_two)

output:
List one <List two: True
List one > List two: False
List one < =List two: True
List one >=List two: True
List one ==List two: False
b) indexing
#Define a list
lst = [10, 20, 30, 40, 50, 60, 70]

print("Original list =", list)

# Access elements using index


print("Element at 0th position =", lst[0])
print("Element at 1st position =", lst[1])
print("Element at 2nd position =", lst[2])
print("Element at 3rd position =", lst[3])

# Access elements using negative index


print("Element at -1th position =", lst[-1])
print("Element at -2th position =", lst[-2])

output:
Original list = [10, 20, 30, 40, 50, 60, 70]
Element at 0th position = 10
Element at 1st position = 20
Element at 2nd position = 30
Element at 3rd position = 40
Element at -1th position = 70
Element at -2th position = 60
c). slicing

list1 = ['H', 'E', 'L','L','O', 'P', 'Y', 'T', 'H', 'O', 'N']
print("Original List:", list1)
sliced_list = list1[3:8]
print("Sliced elements in range 3-8:",sliced_list)
sliced_list1 = list1[5:]
print("Elements sliced from 5th element till the end:",sliced_list1)
sliced_list2 = list1[5:7]
print("Elements sliced from 5 to 7:", sliced_list2)
sliced_list3 = list1[:]
print("All elements using slice operation:",sliced_list3)

OUTPUT:

Original List: ['H', 'E', 'L', 'L', 'O', 'P', 'Y', 'T', 'H', 'O', 'N']
Sliced elements in range 3-8: ['L', 'O', 'P', 'Y', 'T']
Elements sliced from 5th element till the end: ['P', 'Y', 'T', 'H', 'O', 'N']
Elements sliced from 5 to 7: ['P', 'Y']
All elements using slice operation: ['H', 'E', 'L', 'L', 'O', 'P', 'Y', 'T', 'H',
'O', 'N']

comprehension
# Program: Using list comprehensions in different ways

# Generate a list of squares from 1 to 10


squares = [x**2 for x in range(1, 11)]
print("Squares:", squares)

# Get all even numbers between 1 and 20


evens = [x for x in range(1, 21) if x % 2 == 0]
print("Even numbers:", evens)

# Convert a list of words to uppercase


words = ["python", "is", "awesome"]
upper_words = [[Link]() for word in words]
print("Uppercase words:", upper_words)

# Create a list of tuples (number, square)


num_square_pairs = [(x, x**2) for x in range(1, 6)]
print("Number-Square pairs:", num_square_pairs)

# Flatten a list of lists


matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flattened = [num for row in matrix for num in row]
print("Flattened list:", flattened)

# Replace negative numbers with 0 in a list


numbers = [-3, -1, 0, 2, 5, -7]
non_negative = [x if x >= 0 else 0 for x in numbers]
print("No negatives:", non_negative)

Output:
Squares: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Even numbers: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
Uppercase words: ['PYTHON', 'IS', 'AWESOME']
Number-Square pairs: [(1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
Flattened list: [1, 2, 3, 4, 5, 6, 7, 8, 9]
No negatives: [0, 0, 0, 2, 5, 0]
7. Code, execute and debug programs
a) perform basic operations on Dictionary
college = {
"name": "BGS",
"code": "541",
"id": "91BGS"
}
print("Original Dictionary:", college)
college["location"] = "Bellur"
print("\nAfter adding location:", college)
college["location"] = "Byraveshwara Nagar"
print("\nAfter updating location:", college)
[Link]("code")
print("\nAfter removing 'code':", college)
print("\nLength of dictionary:", len(college))

output:
Original Dictionary: {'name': 'BGS', 'code': '541', 'id': '91BGS'}
After adding location: {'name': 'BGS', 'code': '541', 'id': '91BGS', 'location':
'Bellur'}
After updating location: {'name': 'BGS', 'code': '541', 'id': '91BGS', 'location':
'Byraveshwara Nagar'}
After removing 'code': {'name': 'BGS', 'id': '91BGS', 'location': 'Byraveshwara
Nagar'}
Length of dictionary: 3
c). Code, execute and debug programs to perform Dictionary indexing
Iterating comprehension.
number = range(10)
new_dict={}
for n in number:
if n%2 == 0:
new_dict[n]=n**2
print(new_dict)
a_dict ={"a":1,"b":2,"c":3}
key_list=list(a_dict)
print(key_list[2])
print(a_dict["a"])
output:
{0: 0}
c
1
{0: 0, 2: 4}
c
1
{0: 0, 2: 4, 4: 16}
c
1
{0: 0, 2: 4, 4: 16, 6: 36}
c
1
{0: 0, 2: 4, 4: 16, 6: 36, 8: 64}
c
1
8. Code, execute and debug programs to
a). perform string manipulation.
pi = 3.14
s = "Venkata"
v = "Subramanyam"
print("The value of pi is:", pi)
print("The value of v is:", v)
st = s + v
print("After concatenating s and v, the string is:", st)
text = "The value of pi is " + str(pi)
print(text)
length = len(s)
print("Length of s:", length)
print("Number of spaces in v:", [Link](' '))
print("Reversed string s:", ''.join(reversed(s)))
print("Uppercase of v:", [Link]())
print("Last 3 characters of v:", v[-3:])
output:
The value of pi is: 3.14
The value of v is: Subramanyam
After concatenating s and v, the string is: VenkataSubramanyam
The value of pi is 3.14
Length of s: 7
Number of spaces in v: 0
Reversed string s: atakneV
Uppercase of v: SUBRAMANYAM
Last 3 characters of v: yam
b). Program to perform basic array manipulation

from array import *


num = array('i', [1, 3, 5, 7, 9])
print("Original array:", num)
[Link](15)
print("After appending 15 at the end of array:", num)
print("Array elements are:")
for i in num:
print(i)

output:

Original array: array ('i', [1, 3, 5, 7, 9])


After appending 15 at the end of array: array ('i', [1, 3, 5, 7, 9, 15])
Array elements are:
1
3
5
7
9
15
9. Code, execute and debug programs to solve the given problem
a) by defining a function.
def simple_interest(p,t,r):
return (p*t*r)/100
p=float(input("Enter the principal interest= "))
t=float(input("Enter the time in year = "))
r=float(input("Enter the rate of interest = "))
print("simple interest:",simple_interest(p,t,r))

OUTPUT:

Enter the principal interest= 50000


Enter the time in year = 3
Enter the rate of interest = 4
simple interest: 6000.0

OR
def sum(a,b):
return a+b
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
print("sum=",sum(a,b))

OUTPUT:
Enter the value of a:23
Enter the value of b:4
sum= 27
b). using built in functions:

numbers = [5, 10, 15, 20]


print("Numbers:", numbers)
print("Length:", len(numbers))
print("Maximum:", max(numbers))
print("Minimum:", min(numbers))
print("Sum:", sum(numbers))
print("Sorted List:", sorted(numbers))

OUTPUT:
Numbers: [5, 10, 15, 20]
Length: 4
Maximum: 20
Minimum: 5
Sum: 50
Sorted List: [5, 10, 15, 20]
c). using recursion
import math
def print_till_zero(n):
if n<=0:
return
print(n)
n=n-1
print(n)
n=n-1
print_till_zero(n)
print_till_zero(10)

OUTPUT:
10
9
8
7
6
5
4
3
2
1
d). Define anonymous function and code to solve the given problem.

x=lambda a:a+10
print(x)
print("sum=",x(20))

OUTPUT:
<function <lambda> at 0x000002D2DEF97CA0>
sum= 30
10). Code, execute and debug programs using built in modules
import math
print([Link](25))
print([Link])
print([Link](2))
print([Link](60))
print([Link](2))
print([Link](0.5))
print([Link](0.4))
print([Link](4))

OUTPUT:
5.0
3.141592653589793
114.59155902616465
1.0471975511965976
0.9092974268256817
0.8775825618903728
0.4227932187381618
24
11). Code, execute and debug programs
a).using NumPy module

import numpy as np
x = [Link](12).reshape((2,6))
print("Original array:")
print(x)
r1 = [Link](x)
print("Median of said array:")
print(r1)

OUTPUT:
Original array:
[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]]
median of said array:
5.5
b). Code, execute and debug programs using series.

import pandas as pd
s = [Link]([10, 20, 30, 40])
print("Series:", s)
print("Sum =", [Link]())

OUTPUT:
Series:
0 10
1 20
2 30
3 40
dtype: int64
Sum = 100
c). Code, execute and debug programs using data frames.
data = {
'Name': ['Megha', 'Ravi', 'Sneha'],
'Age': [20, 21, 22],
'Marks': [85, 90, 78]
}
df = [Link](data)
print("Student DataFrame:")
print(df)
print("\nNames:", df['Name'])
print("\nAverage Marks:", df['Marks'].mean())
df['Result'] = ['Pass' if m >= 80 else 'Fail' for m in df['Marks']]
print("\nUpdated DataFrame:")
print(df)

OUTPUT:
Student Data Frame:

Name Age Marks


0 Megha 20 85
1 Ravi 21 90
2 Sneha 22 78

Names: 0 Megha
1 Ravi
2 Sneha
Name: Name, dtype: object

Average Marks: 84.33333333333333

Updated Data Frame:


Name Age Marks Result
0 Megha 20 85 Pass
1 Ravi 21 90 Pass
2 Sneha 22 78 Fail
12.) write code snippet to perform following operations on different types of
files

a). write to file.

fileptr=open("[Link]","w")
[Link]("hello world!....")
[Link]()
fileptr=open("[Link]","r")
print([Link]())

output:
hello world!...

b).read file
fileptr=open("[Link]","r")
content=[Link]()
print(type(content))
print(content)
[Link]()

OUTPUT:
<class 'str'>
hello world!......
CONTENT BEYOND SYLLABUS:
a). Exception Handling:
try:
a=int(input("Enter a:"))
b=int(input("Enter b:"))
c=a/b
print("a/b=%d"%c)
except ZeroDivisionError:
print("can't divide by zero")
else:
print("Hi I am else block")

OUTPUT:
Case1:
Enter a:5
Enter b:0
can't divide by zero

Case2:
Enter a:6
Enter b:2
a/b=3
Hi I am else block
b). Exception Handling (using finally block):
try:
num=int(input("Enter the number:"))
result=10/num
except ZeroDivisionError:
print("can't divide by zero")
except ValueError:
print("Invalid input")
else:
print("Result:”, result)
finally:
print("program execution completed")
OUTPUT:
Case 1:
Enter the number:0
can't divide by zero
program execution completed

case2:
Enter the number: g
Invalid input
program execution completed

case 3:
Enter the number:2
Result: 5.0
program execution completed

You might also like