-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
WEEK 6/2.Tuples ,DIctionaries and Sets/6.Predict the Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
WEEK 6/2.Tuples ,DIctionaries and Sets/7.Predict the Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |