diff --git a/Basics/Exercise/5_lists/5_lists_exercise.py b/Basics/Exercise/5_lists/5_lists_exercise.py index 09e3fb40..0ba8c102 100644 --- a/Basics/Exercise/5_lists/5_lists_exercise.py +++ b/Basics/Exercise/5_lists/5_lists_exercise.py @@ -1,4 +1,4 @@ -# 1. Let us say your expense for every month are listed below, +# 1. Let us say your expenses for every month are listed below, # 1. January - 2200 # 2. February - 2350 # 3. March - 2600 @@ -7,36 +7,36 @@ # # Create a list to store these monthly expenses and using that find out, # -# 1. In Feb, how many dollars you spent extra compare to January? -# 2. Find out your total expense in first quarter (first three months) of the year. +# 1. In Feb, how many dollars did you spend extra compared to January? +# 2. Find out your total expenses in the first quarter (first three months) of the year. # 3. Find out if you spent exactly 2000 dollars in any month -# 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list -# 5. You returned an item that you bought in a month of April and -# got a refund of 200$. Make a correction to your monthly expense list +# 4. June month just finished and your expense is 1980 dollars. Add this item to our monthly expense list +# 5. You returned an item you bought in April and +# got a refund of 200$. Correct your monthly expense list # based on this exp = [2200,2350,2600,2130,2190] -# 1. In Feb, how many dollars you spent extra compare to January? -print("In feb this much extra was spent compared to jan:",exp[1]-exp[0]) # 150 +# 1. In Feb, how many dollars did you spend extra compared to January? +print("In feb this much extra was spent compared to Jan:",exp[1]-exp[0]) # 150 -# 2. Find out your total expense in first quarter (first three months) of the year +# 2. Find out your total expenses in first quarter (first three months) of the year print("Expense for first quarter:",exp[0]+exp[1]+exp[2]) # 7150 # 3. Find out if you spent exactly 2000 dollars in any month print("Did I spent 2000$ in any month? ", 2000 in exp) # False -# 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list +# 4. June month just finished and your expense is 1980 dollars. Add this item to our monthly expense list exp.append(1980) print("Expenses at the end of June:",exp) # [2200, 2350, 2600, 2130, 2190, 1980] -# 5. You returned an item that you bought in a month of April and -# got a refund of 200$. Make a correction to your monthly expense list +# 5. You returned an item that you bought in the month of April and +# got a refund of 200$. Correct your monthly expense list # based on this exp[3] = exp[3] - 200 print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190, 1980] -# 2. You have a list of your favourite marvel super heros +# 2. You have a list of your favourite Marvel superheroes # heros=['spider man','thor','hulk','iron man','captain america'] # Using this list @@ -50,6 +50,8 @@ # so remove it from the list first and then add it after 'hulk' heros.remove('black panther') heros.insert(3,'black panther') +#a generalized way of looking for the index without counting the index manually would be helpful in case of longer lists. so it can also be done as follows: +heros.insert(heros.index('hulk')+1,'black panther') print(heros) # 4. Now you don't like thor and hulk because they get angry easily :) # So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool).