Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aujasvit Datta (220254) Assignments 1,2,3 #11

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 220254_Aujasvit/Assignment_1/q6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def input_info():
name = input("Enter name: ").strip()
roll_no = int(input("Enter Roll Number: ").strip())
return (name, roll_no)

def print_info(name, roll_no):
print("Name:", name)
print("Roll Number:", roll_no)


inp_name, inp_roll = input_info()
print('\n') #makes output more readable
print_info(inp_name, inp_roll)
5 changes: 5 additions & 0 deletions 220254_Aujasvit/Assignment_1/q7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def hello_world():
print("Hello, world!")


hello_world() #function call which prints hello world
5 changes: 5 additions & 0 deletions 220254_Aujasvit/Assignment_1/q8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sum = 0
for i in range(1, 11):
sum += i

print("Sum of first ten natural numbers is", sum)
5 changes: 5 additions & 0 deletions 220254_Aujasvit/Assignment_2/q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.bar(['A', 'B', 'C'],[2,3,4], width = 0.5, color = ['red', 'blue', 'green'])
plt.show()
20 changes: 20 additions & 0 deletions 220254_Aujasvit/Assignment_2/q2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#Marks in various subjects
math = pd.Series([94, 98, 64], index = ["Jon", "Jane", "Charlie"])
science = pd.Series([88, 82, 60], index = ["Jon", "Jane", "Charlie"])
sst = pd.Series([79, 66, 80], index = ["Jon", "Jane", "Charlie"])

x = np.arange(3)
df = pd.DataFrame({'Math': math, 'Science': science, "SST": sst})

plt.bar(x - 0.1, df['Math'].values, width = 0.1)
plt.bar(x, df['Science'].values, width = 0.1)
plt.bar(x + 0.1, df['SST'].values, width = 0.1)
plt.xticks(x, ['Jon', 'Jane', 'Aujasvit'])
plt.xlabel('Student')
plt.ylabel('Marks')
plt.legend(['Math', 'Science', 'SST'])
plt.show()
8 changes: 8 additions & 0 deletions 220254_Aujasvit/Assignment_2/q3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
x = [1,2,3,4,6, 7]
y = [2,1,5,3,10,7]
plt.scatter(x, y, color = 'red')
plt.plot(x, y)
plt.show()
14 changes: 14 additions & 0 deletions 220254_Aujasvit/Assignment_2/q4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
a = np.array([1,2, 5, 3])
print('a:', a)
print("Sum of all elements in a:", np.sum(a))
print("Product of all elements in a:", np.prod(a))
print("a squared:", a**2)
print("2 to the power a:", 2**a)
print("a + 1:", a + 1)
print("a * 10:", a * 10)
print("Mean of elements of a:", np.mean(a))
print("Median of elements of a:", np.median(a))
print("Standard Deviation of elements of a:", np.std(a))
8 changes: 8 additions & 0 deletions 220254_Aujasvit/Assignment_3/problem1/activation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np


def sigmoid(a):
return 1/(1 + np.exp(-1*a))

def tanh(a):
return (np.exp(a) - np.exp(-a))/(np.exp(a) + np.exp(-a))
22 changes: 22 additions & 0 deletions 220254_Aujasvit/Assignment_3/problem1/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')


def sigmoid(a):
return 1/(1 + np.exp(-1*a))

def tanh(a):
return (np.exp(a) - np.exp(-a))/(np.exp(a) + np.exp(-a))

x = np.linspace(-10, 10, 1000000)

plt.plot(x, sigmoid(x))
plt.xlabel('x')
plt.ylabel('sigmoid(x)')
plt.show()

plt.plot(x, tanh(x))
plt.xlabel('x')
plt.ylabel('tanh(x)')
plt.show()
17 changes: 17 additions & 0 deletions 220254_Aujasvit/Assignment_3/problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('default')

x = pd.read_csv('/content/World Press Index 2021.csv')
temp = np.arange(2)

best_2019 = x['Global Score 2019'].min()
best_2019_country = str(x[x['Global Score 2019'] == best_2019]['Country Name']).split()[1]

worst_2021 = x['Global Score 2021'].max()
worst_2021_country = str(x[x['Global Score 2021'] == x['Global Score 2021'].max()]['Country Name']).split()[1]

plt.bar([worst_2021_country + ': Worst Global Score 2019', best_2019_country + ': Best Global Score 2021'], [worst_2021,best_2019,], width = 0.1)
plt.show()