Finding a Value in a List¶

Create a list with ten random values from 1-50. Display those values on the screen, and then prompt the user for an integer. Search through the list, and if the item is present, say so. It is not necessary to display anything if the value was not found. If the item is in the list multiple times, it’s okay if the program prints the message more than once.

Do not use any built-in methods like list.index() or the in operator. Use a loop to manually search the list.

Name your file find_value_in_list.py

List: 45 39 32 12 44 50 26 42 16 20
Value to find: 42

42 is in the list.
List: 45 39 32 12 44 50 26 42 16 20
Value to find: 43
List: 24 30 31 24 32 33 34 24 35 36
Value to find: 24

24 is in the list.
24 is in the list.
24 is in the list.

©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing