Intermediate Python - 13.2 Practice - Getting a Raise - help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Intermediate Python - 13.2 Practice - Getting a Raise - help

Problem: You work on a payroll program. Given a list of salaries, you need to take the bonus everybody is getting as input and increase all the salaries by that amount. Output the resulting list. Current attempt, have tried several iterations: salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) result = list(map(bonus, salaries)) print(result) Not sure what to do? Please help, thanks!

4th Jul 2021, 6:32 PM
Zach Z
10 Answers
+ 13
Zach Z , the use of map() function needs a function that will be applied to each element in the salaries list. this can be a lambda function as mentioned from I ᴀᴍ "Tɪᴍᴇ" . but it can also be a regular function, if you feel more comfortable with that: (this is your code slightly adjusted) def add(salary): return salary + bonus salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) result = list(map(add, salaries)) print(result) but this task can also be solved by using a loop.
4th Jul 2021, 7:24 PM
Lothar
Lothar - avatar
+ 5
Zach Z Use lambda: list(map (lambda x : x + bonus, salaries))
4th Jul 2021, 6:46 PM
A͢J
A͢J - avatar
+ 3
Map() Function: salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) def add_bonus(x): return x + bonus result = list(map(add_bonus, salaries)) print(result)
7th Aug 2021, 10:29 AM
Aziz Ergashev
Aziz Ergashev - avatar
5th Jul 2021, 5:59 PM
Zach Z
+ 1
def add(amount): return amount + bonus salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) toatal = list(map(add, salaries)) print(toatal)
16th Aug 2022, 8:58 AM
Abdul Ghafar
Abdul Ghafar - avatar
+ 1
With For loop salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) listbonus=[] for i in salaries: listbonus.append(i+bonus) print(listbonus)
8th Nov 2022, 10:11 PM
Hebert Aranda
+ 1
My Answer: def add(salary): return salary + bonus salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) result = list(map(add, salaries)) print(result)
10th Nov 2022, 8:24 AM
Pooja Patel
Pooja Patel - avatar
0
salaries = [2000, 1800, 3100, 4400, 1500] bonuses = int(input()) result = list(map(lambda bonus: bonus + bonuses, salaries)) print(result)
16th Dec 2021, 10:06 PM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int salaryBudget = Convert.ToInt32(Console.ReadLine()); int percent = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Before the increase: " + salaryBudget); //complete the method call Increase(ref salaryBudget, percent); Console.WriteLine("After the increase: " + salaryBudget); } //complete the method static void Increase(ref int x, int y) { x = (x * (100 + y )) / 100; } } } This code works 100 percent without error.
6th Jun 2022, 12:02 PM
Mohammed Afzal Hussain
Mohammed Afzal Hussain - avatar
0
salaries = [2000, 1800, 3100, 4400, 1500] bonus = int(input()) salaries = list(map(lambda x: x + bonus, salaries)) print(salaries)
8th Apr 2024, 9:44 AM
Rashmi Kulkarni