Skip to content

Commit 07a4973

Browse files
committed
Initial commit
0 parents  commit 07a4973

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1663
-0
lines changed

Diff for: Ass1_1.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
start = 1
2+
stop = 249
3+
4+
sum = 0
5+
6+
for number in range(start, stop):
7+
if number % 2 != 0:
8+
sum += number
9+
10+
print(str(number) + ' ', end='')
11+
12+
print()
13+
print("Sum of all odd numbers in the interval [1, 249]: " + str(sum))

Diff for: Ass1_21.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
x = 0
2+
y = 1
3+
4+
print(str(y), end=' ')
5+
6+
z = x+y
7+
8+
start = 1
9+
stop = 10
10+
11+
for num in range(start, stop):
12+
#if num < stop:
13+
print(str(z), end=' ')
14+
x=y
15+
y=z
16+
z=x+y
17+
18+
19+
20+

Diff for: Ass1_22.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
a=0
2+
b=0
3+
c=1
4+
print (str(c), end = ' ')
5+
start = 1
6+
end = 10
7+
d=a + b + c
8+
9+
for x in range(start, end ):
10+
print(d , end =' ')
11+
a = b
12+
b = c
13+
c = d
14+
d = a + b + c

Diff for: Ass1_23.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
num1=1
2+
num2=3
3+
print(str(num1) + ' ' + str(num2), end=' ')
4+
index=2
5+
counter=1
6+
while index < 20:
7+
if index%2==0:
8+
num3=num1+num2
9+
print(str(num3), end=' ')
10+
num1=2*num3
11+
else:
12+
num4=(index-counter)*3
13+
print(str(num4), end=' ')
14+
num2=num4
15+
counter+=1
16+
index+=1

Diff for: Ass1_3.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lower = 2
2+
upper = 10000
3+
4+
print("Prime numbers between",lower,"and",upper,"are:")
5+
6+
for num in range(lower, upper):
7+
if num > 1:
8+
for i in range(2,num):
9+
if (num % i) == 0:
10+
break
11+
else:
12+
print(num, end=' ')

Diff for: Ass2_1.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
nums = [-1, 2, 5]
3+
4+
#a=3
5+
for i in range(3, 5):
6+
nums.append((nums[i-3] + nums[i-2] + nums[i-1]/2))
7+
#a=a+1
8+
9+
print(nums)

Diff for: Ass2_2.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
X = [[12,7,3],
3+
[4 ,5,6],
4+
[7 ,8,9]]
5+
6+
Y = [[5,8,1],
7+
[6,7,3],
8+
[4,5,9]]
9+
10+
matrixAddition = [[0, 0, 0],[0,0,0],[0,0,0]]
11+
12+
matrixSubtraction = [[0, 0, 0],[0,0,0],[0,0,0]]
13+
14+
# iterate through rows
15+
print("Matrix addition")
16+
for i in range(len(X)):
17+
# iterate through columns
18+
for j in range(len(X[0])):
19+
matrixAddition[i][j] = X[i][j] + Y[i][j]
20+
21+
for r in matrixAddition:
22+
print(r)
23+
24+
print()
25+
26+
print("Matrix subtraction")
27+
for i in range(len(X)):
28+
for j in range(len(X[0])):
29+
matrixSubtraction[i][j] = X[i][j] - Y[i][j]
30+
31+
for r in matrixSubtraction:
32+
print(r)
33+
34+
print()
35+
36+
matrix1 = [[12,7,3], [4 ,5,6], [7 ,8,9]]
37+
# 3x4 matrix
38+
matrix2 = [[5,8,1,2], [6,7,3,0],[4,5,9,1]]
39+
# result is 3x4
40+
matrixMutiplication = [[0,0,0,0],[0,0,0,0],[0,0,0,0]]
41+
42+
# iterate through rows of X
43+
print("Matrix multiplication")
44+
for i in range(len(matrix1)):
45+
# iterate through columns of Y
46+
for j in range(len(matrix2[0])):
47+
# iterate through rows of Y
48+
for k in range(len(matrix2)):
49+
matrixMutiplication[i][j] += matrix1[i][k] * matrix2[k][j]
50+
51+
for r in matrixMutiplication:
52+
print(r)

Diff for: Ass2_3.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
months = {'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30, 'July': 31,
2+
'August': 31, 'September': 30,'October': 31, 'November': 30, 'December': 31}
3+
4+
#Months which have 30 days
5+
print("Months which have 30 days")
6+
for key in months.keys():
7+
8+
if months.get(key) == 30:
9+
print(key)
10+

Diff for: Ass2_4.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
text = input('Enter some text: ')
2+
3+
splitted_text = text.split()
4+
word_dict={}
5+
for part in splitted_text:
6+
7+
if part not in word_dict:
8+
word_dict.update({part:1})
9+
else:
10+
word_dict.update({part:word_dict.get(part) + 1})
11+
12+
for key in word_dict.keys():
13+
print(key + ':' + str(word_dict.get(key)))
14+
15+
print(word_dict)
16+
17+
18+

Diff for: Ass2_5.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
wordset = set()
2+
text = input('Enter some texts: ')
3+
for word in text.split():
4+
wordset.add(word)
5+
print(wordset)

Diff for: Ass3_1.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import math
2+
3+
def math_sum(value_list):
4+
5+
y = 0
6+
7+
for i in range(len(value_list)):
8+
y += math.pow(math.sin(value_list[i]), 2) - math.log(value_list[i], 3) \
9+
+ 1/math.pow(value_list[i], 5)
10+
11+
return y
12+
13+
value_list = [90,6,8.9]
14+
y=math_sum(value_list)
15+
16+
print("The result of the calculation is: ")
17+
print('{:.2f}'.format(y))

Diff for: Ass3_2.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
text = "name=Milk;amount=200;unit_price=0.9\n" \
2+
"name=Bread;amount=134;unit_price=3.48\n" \
3+
"name=Butter;amount=58;unit_price=1.65\n" \
4+
"name=Cheese;amount=260;unit_price=4.35"
5+
6+
products=text.split("\n")
7+
price_sum = 0
8+
9+
for p in products:
10+
print(p)
11+
product_info = p.split(";")
12+
amount_str = product_info[1].split("=")[1]
13+
price_str = product_info[2].split("=")[1]
14+
price_sum+=eval(amount_str)*eval(price_str)
15+
16+
17+
print("The total price of all products is: ")
18+
print(str(price_sum))
19+

Diff for: Ass3_3.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
def encrypt_text(text):
3+
mapping_table = str.maketrans('flower', 'garlic')
4+
print(text.translate(mapping_table))
5+
6+
text = "A flower is a beautiful plant, which can be planted in the garden or " \
7+
"used to decorate home. One might like a flower for its colors and the " \
8+
"other might like a flower for its smell. A flower typically symbolizes soft feelings"
9+
10+
#We call the encrypt_text method here
11+
encrypt_text(text)

Diff for: Ass3_4.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import re
2+
3+
text="A flower is a beautiful plant, which can be planted in the garden " \
4+
"or used to decorate home. One might like a flower for its colors and the " \
5+
"other might like a flower for its smell. A flower typically symbolizes soft feelings"
6+
7+
for x in re.finditer('flower', text):
8+
print("flower indexes are: ", x.start(), x.end())
9+
10+
11+
12+
13+

Diff for: Ass4_1.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#a program which fires with f and quits with q
2+
import turtle
3+
import time
4+
5+
screen = turtle.Screen()
6+
t = turtle.Turtle()
7+
8+
9+
def fire():
10+
x = -400
11+
y = -350
12+
13+
for i in range(70):
14+
t.setx(x)
15+
t.sety(y)
16+
t.dot(10, 'red')
17+
x += 10
18+
y += 10
19+
20+
21+
for i in range(100):
22+
t.goto(x, -350)
23+
t.dot(10, 'red')
24+
25+
26+
27+
def quit():
28+
turtle.bye()
29+
30+
31+
ch = input('enter f to fire or q to quit !')
32+
33+
if ch == 'f':
34+
fire()
35+
elif ch == 'q':
36+
quit()

Diff for: Ass4_2.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import turtle
2+
import time
3+
screen = turtle.Screen()
4+
5+
6+
s=turtle.Screen()
7+
t=turtle.Turtle()
8+
t.hideturtle()
9+
t.penup()
10+
t.setx(-20)
11+
t.sety(-120)
12+
t.pendown()
13+
t.pensize(3)
14+
t.circle(100)
15+
t.penup()
16+
t.setx(0)
17+
t.sety(0)
18+
t.setx(-50)
19+
t.setheading(150)
20+
t.pendown()
21+
t.circle(50, 60)
22+
t.penup()
23+
#Here we set coordinates for left eye
24+
t.setx(-75)
25+
t.sety(-10)
26+
t.pendown()
27+
#Here we draw left eye
28+
t.dot(10)
29+
t.penup()
30+
#Here we draw the right eyebrow
31+
t.setx(50)
32+
t.sety(0)
33+
t.setheading(150)
34+
t.pendown()
35+
t.circle(50, 60)
36+
#Here we draw the right eye
37+
t.penup()
38+
t.setx(25)
39+
t.sety(-10)
40+
t.pendown()
41+
t.dot(10)
42+
#Here we draw the nose
43+
t.penup()
44+
t.setx(-20)
45+
t.sety(-20)
46+
t.pendown()
47+
t.pensize(5)
48+
t.goto(-20,-50)
49+
#Here we draw the mouth
50+
t.penup()
51+
t.setx(-27)
52+
t.sety(-80)
53+
t.setheading(0)
54+
t.pendown()
55+
t.circle(90, 10)
56+
#Animation control
57+
for i in range(1000):
58+
turtle.stamp()
59+
turtle.update()
60+
time.sleep(3)

0 commit comments

Comments
 (0)