Write a program that uses the following initializer list to find if a random value entered by a user is part of that list.
v = [24, 20, 29, 32, 34, 29, 49, 46, 39, 23, 42, 24, 38]
The program should ask the user to enter a value. If the value is in the array, the program should print the index. If it is not in the array, the program should print -1.
Hint: The values in the list are integers, so you should also get the value from the user as an integer. We can assume the user will only enter integer values.
BestStudentSince2004:
Python?
Answers
Answered by
7
My Python answer
v = [24, 20, 29, 32, 34, 29, 49, 46, 39, 23, 42, 24, 38]
def check():
num = input('Enter number')
if num in v:
print(v.index(num))
else:
print('-1')
Similar questions
Math,
2 months ago
Business Studies,
2 months ago
Geography,
5 months ago
English,
11 months ago
Math,
11 months ago