-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
55 additions
and
13 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,18 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp strings | ||
|
||
print('Question: for sets A and B return all pairs {A(i) , B(-i)}') | ||
|
||
|
||
l1 = ["hi","hello","bye"] | ||
l2 = ["shivam",'raj','roy'] | ||
|
||
for i in range(len(l1)): | ||
print(l1[i]+" "+l2[-(i+1)]) | ||
# match first element of l1, | ||
# with last element of l2 | ||
|
||
#single line | ||
res = [(l1[i],l2[-i-1]) for i in range(len(l1))] | ||
|
||
print('Answer:') | ||
print(res) |
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,24 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp Everything till for loops | ||
|
||
print('Question: reverse each word of string') | ||
|
||
sentence = 'hello world how are you' | ||
res = '' | ||
|
||
# what to reverse? | ||
# reverse upto the space | ||
left = 0 | ||
while left < len(sentence): | ||
right = sentence.find(' ',left) | ||
if right == -1: | ||
right = len(sentence) | ||
word = sentence[left:right] | ||
# now add this reversed word to result! | ||
print(res) | ||
res += word[::-1] | ||
left = right | ||
#now start from here | ||
|
||
print('Answer:') | ||
print(res) | ||
|
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp lists | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp strings | ||
|
||
print('Question: simulate game where raj can pick the chocolate from either edge of list, he will always pick the bigger one') | ||
print('Question: for sets A and B return all pairs {A(i) , B(-i)}') | ||
|
||
chocolates = [1,3,4,5,6] | ||
|
||
while len(chocolates) > 1: | ||
#check who is bigger first or last? | ||
if chocolates[0] > chocolates[-1]: | ||
# what if first is bigger? | ||
eat = chocolates.pop(0) | ||
else: | ||
eat = chocolates.pop() | ||
print('Eating ',eat) | ||
l1 = ["hi","hello","bye"] | ||
l2 = ["shivam",'raj','roy'] | ||
|
||
print('Answer:') | ||
print('Left with chocolate',chocolates[0]) | ||
for i in range(len(l1)): | ||
print(l1[i]+" "+l2[-(i+1)]) | ||
# match first element of l1, | ||
# with last element of l2 | ||
|
||
#single line | ||
res = [(l1[i],l2[-i-1]) for i in range(len(l1))] | ||
|
||
print('Answer:') | ||
print(res) |