I am have been trying to learn how to manipulate lists. Example I have successfully done a simple program that asks the user for a numerical input and returns the corresponding month. Below is an example of what my solution is:
months = ['January', 'February',
'March', 'April', 'May',
'June', 'July', 'August',
'September', 'October', 'November', 'December']
n = int(input("Enter a value between 1 and 12: "))
# Process & Output:
if 1 <= n <= 12:
print ("The month is", months[n-1])
else:
print ("Value is out of the range")
My current question is, how would I go about asking the user to pick from the list but by inputting a string rather than an int
value?
Example:
subjects= ['Maths','English','Science','History','Business']
n = (input("What is your favourite subject this semester? "))
I would not be able to use the above method because it requires an int
value.