0% found this document useful (0 votes)
26 views2 pages

Import Import Def: "Name: Muhammad Ammad" "Reg No: 9745" "Class Id: 105034"

This document contains code snippets that demonstrate various Python functions and operations. It prints out student details, calculates standard deviation of a data set, filters even numbers from a list, slices lists, and defines and calls a function.

Uploaded by

talha khan
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)
26 views2 pages

Import Import Def: "Name: Muhammad Ammad" "Reg No: 9745" "Class Id: 105034"

This document contains code snippets that demonstrate various Python functions and operations. It prints out student details, calculates standard deviation of a data set, filters even numbers from a list, slices lists, and defines and calls a function.

Uploaded by

talha khan
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
You are on page 1/ 2

8/31/2020 Untitled2

In [11]: print("Name: Muhammad Ammad")


print("Reg No: 9745")
print("Class Id: 105034")

import math
import sys

def std_dev_calc(data):
n = len(data)

if n <= 1:
return 0.0

mean, std_dev = avg_calc(data), 0.0

for el in data:
std_dev += (float(el) - mean)**2
std_dev = math.sqrt(std_dev / float(n-1))

return std_dev

data = [76,84,69,92,58,89,73,97,85,77]
print("Standard Deviation : ",std_dev_calc(data))

Standard Deviation : 11.709445380166864

localhost:8888/notebooks/Untitled2.ipynb 1/2
8/31/2020 Untitled2

In [9]: a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
print("Printing Entire List " ,a)

even = [num for num in a if num % 2 == 0]


print("Even numbers in the list: ", even)

print ("The last element is : " + str(a[-1]))


print ("The 3rd last element is : " + str(a[-3]))
print("Reversed array:",a[::-1])
print("4th to 10th Index:",a[4:10])
print("First 8 Elements:",a[0:8])
print("Last 4 Elements:",a[16:20])

Printing Entire List [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Even numbers in the list: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
The last element is : 20
The 3rd last element is : 18
Reversed array: [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
4th to 10th Index: [5, 6, 7, 8, 9, 10]
First 8 Elements: [1, 2, 3, 4, 5, 6, 7, 8]
Last 4 Elements: [17, 18, 19, 20]

In [10]: import math

def myfun(x):
return math.cos(x) - x**3
print('Result is ', myfun(2))

Result is -8.416146836547142

In [ ]:

localhost:8888/notebooks/Untitled2.ipynb 2/2

You might also like