Computer Science, asked by gklewis2004, 2 months ago

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?
gklewis2004: yes

Answers

Answered by BestStudentSince2004
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