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]
2 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]2 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
You can install several printers on your machine, but at least one must be the _______ printer.
Digiron [165]
<span>You can install several printers on your machine, but at least one must be the default printer.
When you have several machines attached to your computer, it is important to designate one of them as the 'default' machines so as to avoid confusion within the system. If you fail to do this, you may create some problems, so be sure to choose a default one.</span>
3 0
3 years ago
Which one of these are a valid IPv4 address?
Harman [31]

Answer:

1.1.1.1, 54.45.43.54, and 255.255.255.0

3 0
1 year ago
Using your own computer, give the name of the operating system that runs it and give examples of five legal file names. Then cre
Vika [28.1K]

Answer:

Name of Operating System: Ubuntu

Five legal file names:

inventory.txt

total.txt

NIKKAH.txt

Defaulter.txt

studenT.txt

Five illegal file names:

wel/come.txt

..

MY>note.txt

.

my<work.yxt

Explanation:

To fix the illegal name:

1. Remove the special character, so it becomes welcome.txt

2. Remove the double dot and rename using text characters

3. Remove the special character, so it becomes MYnote.txt

4. A file cannot be named using dot. So we rename to a textual name

5. Remove the special character, so it becomes mywork.txt

Some additional rule for naming of files legally in Unix is that, you cannot use a reserved word to name your file. Starting a file name with number is allowed. Starting a file name with dot make the file to be hidden.

7 0
2 years ago
To use an imported image, simply drag it from the desktop onto the stage. true or false?
elena-s [515]

Answer:

True

Explanation:

Because i have done it before and it works on an accer

6 0
3 years ago
Ben would like to let everyone in the class know about the topic his group is researching.
Rasek [7]
I think the best way is to email
6 0
3 years ago
Other questions:
  • Morgan is the operations manager for a national appliance distributor. The company has offices throughout the United States. Com
    7·1 answer
  • Nadia would like to find text in her current document that differentiates CompanyABC from companyabc. Which option should she us
    8·2 answers
  • One of the most famous ___ licenses is gpl, which ensures that a particular program remains free to distribute and allows its co
    10·1 answer
  • Which folder is the default choice for saving bitmap or JPEG files created by a user?
    9·1 answer
  • If you wanted to create a graph that showed how much each value contributed to the whole value, you would use a _____.
    15·2 answers
  • Computers store temporary Internet files in the Recycle Bin. These files take up space and slow down a computer. Which tool can
    10·1 answer
  • Can anybody answer this
    11·1 answer
  • A method that determines if a list is empty in a consistently written linked list class that uses a reference first to point to
    13·2 answers
  • what is cicada 3301? i will give brainliest if you give me a correct answer (not copy and pasted) and somewhat well detailed, i
    8·1 answer
  • The use of technology to observe a user's actions often without the user's knowledge is known as:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!