-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterview_short_questions.py
More file actions
58 lines (41 loc) · 1.19 KB
/
interview_short_questions.py
File metadata and controls
58 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Some short python interview problems.
# ### Print pairs of values
# input_list = ['a', 'b', 'c', 'd', 'e']
# # (a,b) and (b,a) both included
# pairs_01 = []
# for outer in input_list:
# for inner in input_list:
# pairs_01.append((outer, inner))
# print(f"Both included: {pairs_01}")
# # (a,b) or (b,a) included
# pairs_02 = []
# for outer in range(len(input_list)):
# for inner in input_list[outer:]:
# pairs_02.append((input_list[outer], inner))
# print(f"Unique: {pairs_02}")
# ### Reverse a string without using reverse
# def reverse_string(input_str):
# length = len(input_str)
# output_str = ''
# for i in range(length-1, -1, -1):
# output_str += input_str[i]
# return output_str
# print(reverse_string('abcde'))
### What does this print?
def print_something(value):
if value == 'a':
print("Option one")
elif value == 'b':
exit()
print("Option two")
else:
print("Option three")
print("Option four")
return(value)
for v in ['a', 'b', 'c']:
returns = print_something(v)
print(returns)
# Output:
# Option one
# Option four
# a