Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-er committed Sep 28, 2023
1 parent 760d3d2 commit 96ed594
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 0 deletions.
6 changes: 6 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/1.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
What will be the output of following code?

a = 5,6,7
print(a[1:])

Answer = (6,7)
9 changes: 9 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/10.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
What will be the output of following code?

d = {1:2, “abc”:5, “def”:7}
if 2 in d:
print(‘Present’)
else:
print(‘Not Present’)

Answer = Not Present
8 changes: 8 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/11.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What will be the output of following code?

a = {1:2,’list’:[1,2],3:5}
b = {4:5,3:7}
a.update(b)
print(a[3])

Answer = 7
8 changes: 8 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/12.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What will be the output of following code?

a = {1:2,’list’:[1,2],3:5}
a.pop(‘list’)
a[‘list’] = [3,5]
print(a[‘list’])

Answer = [3,5]
9 changes: 9 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/13.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
What will be the output of following code?

s = {1,2,3,5,4,2,3,1}
print(len(s),end= “ “)
s.add(4)
s.add(3)
print(len(s))

Answer = 5 5
8 changes: 8 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/14.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What will be the output of following code?

s = {}
s.add(4)
s.add(4)
print(len(s))

Answer = Error
7 changes: 7 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/2.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
What will be the output of follwing code?

a = 5,6,7
a[2] = 9
print(a)

Answer = Error
8 changes: 8 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/3.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What will be the output of following code?

a = 1,2
b = (4,5)
d = (a,b)
print(d[0])

Answer = (1,2)
8 changes: 8 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/4.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What will be the output of follwing code?

a = 1,2
b = (4,5)
d = a+b
print(d[2])

Answer = 4
6 changes: 6 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/5.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
What will be the output of following code?

a = (“ab”,”abc”,”def”)
print(min(a))

Answer = ab
11 changes: 11 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/6.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
What will be the output of following code?

def multiply(a,b,c,*more):
value = a*b*c
for i in more:
value = value * i
return value
V = multiply(1,2,3,4,5)
print(V)

Answer = 120
13 changes: 13 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/7.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
What will be the output of following code?

def sum_multiply(a,b,*more):
sum_value = a+b
m_value = a*b
for i in more:
sum_value += i
m_value*=i
return sum_value,m_value
s_m = sum_multiply(2,3,4)
print(s_m)

Answer = (9,24)
6 changes: 6 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/8.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
What will be the output of following code?

d = {1:2, “abc”:5, “def”:7}
print(d[0])

Answer = Error
6 changes: 6 additions & 0 deletions WEEK 6/2.Tuples ,DIctionaries and Sets/9.Predict the Output
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
What will be the output of following code?

d = {1:2, “abc”:5, “def”:7}
print(d.get(0,5))

Answer = 5
10 changes: 10 additions & 0 deletions WEEK 6/3.Test/1.Print 2D Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
n, m = map(int, input().split())
array_2d = []
for _ in range(n):
row = list(map(int, input().split()))
array_2d.append(row)
for i in range(n):
for _ in range(n - i):
for elem in array_2d[i]:
print(elem, end=" ")
print()
18 changes: 18 additions & 0 deletions WEEK 6/3.Test/2.Minimum Length Word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def find_minimum_length_word(input_string):
words = input_string.split()

min_length_word = words[0]
min_length = len(words[0])

for word in words:
current_length = len(word)
if current_length < min_length:
min_length_word = word
min_length = current_length

return min_length_word

input_string = input()

minimum_length_word = find_minimum_length_word(input_string)
print(minimum_length_word)
17 changes: 17 additions & 0 deletions WEEK 6/3.Test/3.Leaders in array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def find_leaders(arr):
n = len(arr)
leaders = []
max_right = arr[n - 1]

for i in range(n - 1, -1, -1):
if arr[i] >= max_right:
leaders.append(arr[i])
max_right = arr[i]

leaders.reverse()
return leaders

n = int(input())
arr = list(map(int, input().split()))
leaders = find_leaders(arr)
print(*leaders)
23 changes: 23 additions & 0 deletions WEEK 6/3.Test/4.Count And Say.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def writeAsYouSpeak(n):
if n <= 0:
return ""

sequence = "1"

for _ in range(n - 1):
new_sequence = ""
count = 1
current_digit = sequence[0]

for i in range(1, len(sequence)):
if sequence[i] == current_digit:
count += 1
else:
new_sequence += str(count) + current_digit
count = 1
current_digit = sequence[i]

new_sequence += str(count) + current_digit
sequence = new_sequence

return sequence

0 comments on commit 96ed594

Please sign in to comment.