I'm trying to allow for the values of these pre-defined variables to change based on the input of a user.
I've recently come across the map() function, and I tried using that, though I'm not sure if I used that properly.
In this code, I attempted to decrease the percentages of a list of numbers, and then output those modified numbers, based on the user input.
a = 1
b = 2
c = 3
list = [a, b, c]
i = 0
def percentage(n):
while i < 7:
n= n*20/100
i+=1
sample = input("Enter a string: ")
if sample == "Fox":
map(percentage, list)
cat1 = f"The fox ran at a speed of {a}."
cat2 = f"The shark swam at a speed of {b}."
cat3 = f"The bird flew at a speed of {c}."
print(cat1, cat2, cat3)
print(list)
This is the output:
Enter a string: Fox
The fox ran at a speed of 1. The shark swam at a speed of 2. The bird flew at a speed
of 3.
[1, 2, 3]
What I did didn't change the values. Have I done anything wrong? If not, how can I go about achieving what I want to achieve here?