I'm a begginer in Python and i'm trying to do a program when the user chooses a number from a list, then after you type by how you much want to reduce this chosed number and then print the list.
I know that using list[specific index], check if matches with user input and repeating over and over again would do the job, but would be so unoptimized (if there's a way to do this in a single line would be fine), I want to do something that automatically finds the the number of the list by the user input.
Desired Output:
[5, 10, 15, 20]
what number you want from the list?
> 15
by how much you want to subtract?
> 6
>> [5, 10, 9, 20]
my code:
list = [5, 10, 15, 20]
print(list)
number = int(input("what's the number you want from the list?"))
if number in list:
print("by how much you want to subtract?")
remove = int(input())
list[number] = list[number] - remove
print("Done It!")
else:
print("not a valid number")
print(list)