Learn practical skills, build real-world projects, and advance your career
Updated 2 years ago
first
Use the "Run" button to execute the code.
!pip install jovian --upgrade --quiet
import jovian
# Execute this to save new versions of the notebook
jovian.commit(project="first")
[jovian] Error: Failed to read the Jupyter notebook. Please re-run this cell to try again. If the issue persists, provide the "filename" argument to "jovian.commit" e.g. "jovian.commit(filename='my-notebook.ipynb')"
tests = []
test = {
'input': {
'cards' : [13, 11, 10, 7, 4, 3, 1, 0],
'query' : 7
},
'output' : 3
}
tests.append(test)
tests.append({
'input': {
'cards' : [13, 11, 10, 7, 4, 3, 1, 0],
'query' : 13
},
'output' : 0
})
tests.append({
'input': {
'cards' : [13, 11, 10, 7, 4, 3, 1, 0],
'query' : 0
},
'output' : 7
})
tests.append({
'input': {
'cards' : [13, 11, -10, 7, 4, 3, 1,-200],
'query' : -200
},
'output' : 7
})
tests.append({
'input': {
'cards' : [0],
'query' : 0
},
'output' : 0
})
tests.append({
'input': {
'cards' : [13, 11, 10, 7, 4, 3, 1, 0],
'query' : 45
},
'output' : -1
})
def locate_number(cards, query):
position = 0
for card in cards:
if card == query:
return position
position += 1
if position == len(cards):
return -1