1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksklad [387]
3 years ago
12

Q1). Write a python program to pass a list to a function and double the odd values and half even values of a list and display li

st elements after changing.​
Computers and Technology
1 answer:
zepelin [54]3 years ago
8 0

Answer:

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Python.

def f(x):

   new_list=[]

   for i in x:

       if i%2==0:

           new_list.append(i//2)

       else:

           new_list.append(i*2)

   return new_list

   

my_list=list(range(1,6))

print('Original List:',my_list)

my_list=f(my_list)

print('Modified List:',my_list)

\textsf{\large{\underline{Logic}:}}

  1. Create a new list.
  2. Iterate over the list passed into the function.
  3. Check if the element is even or not. If true, append half the value of element in the list.
  4. If false, append twice the value of the element in the list.
  5. At last, return the new list.

There is another way of doing this - By using map() function.

—————————————————————————————

def f(x):

   return list(map(lambda x:x//2 if x%2==0 else 2*x,x))

   

my_list=list(range(1,6))

print('Original List:',my_list)

my_list=f(2my_list)

print('Modified List:',my_list)

—————————————————————————————

\textsf{\large{\underline{O{u}tput}:}}

Original List: [1, 2, 3, 4, 5]

Modified List: [2, 1, 6, 2, 10]

You might be interested in
Martin wants to calculate integer multiples up to 10 for a list of numbers. For example, he needs to multiply the first number i
kifflom [539]
A for loop.






----------------------------
5 0
4 years ago
Which of the following application delivery methods requires Internet access?
morpeh [17]

Answer:Cloud hosted

Explanation:

3 0
3 years ago
Why should one avoid noise in the computer room​
iragen [17]
Is this a joke bc if so why?
5 0
3 years ago
Read 2 more answers
You can't cite Wikipedia, what are three ways that you can use it for your research?
Vlada [557]

Answer:

Scan over the article for references/resources, find general information about your topic, find keywords and terms you can use for further searching.

Explanation:

8 0
3 years ago
Does anyone know what the name of the game is, where you click on the grey dots in a 3x3 grid and try to make them all the same
antoniya [11.8K]

Answer:

Its the pattern puzzle game.

Explanation:

The answer is straight forward. Its a pattern puzzle game, and here we need to change everything to same color, and that is a pattern of this pattern game. Many forms of such pattern games are available, but this one happens to be the most popular among them all, and is widely used by various people of all ages to pass their time.

3 0
3 years ago
Other questions:
  • In the Scrum board, prioritizing the issue backlog is done in the ———- mode.
    7·1 answer
  • Software that people commonly use in the workplace to make their lives easier is called?
    6·1 answer
  • To add text to a slide when using presentation software, you need to add a text box. To add a text box, click the Text Box butto
    8·2 answers
  • How Do I Make A Walk animation for a school Project?? Gifs?
    13·1 answer
  • You are a network consultant who has been asked to attend an initial meeting with the executive management team of ElectroMyCycl
    10·1 answer
  • Write a code that calculates the Greatest Common Divisor (GCD) of two positive integers (user-defined inputs). Include an except
    10·1 answer
  • 4. UPS stands for Uninterrupted Power Supply . (Yes /no
    11·1 answer
  • Come up with a system, using only
    8·1 answer
  • BRAINLIEST TO RIGHT ANSWER!! TIMED QUIZ HELP ASAP PLS!!
    5·1 answer
  • Why header files are needed in every c program ?expalin​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!