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
Create a program that allows the user to pick and enter a low and a high number. Your program should generate 10 random numbers
Natalka [10]

Answer:

import java.util.Scanner;

import java.util.Arrays;

import java.util.Random;

public class Main {

 public static void main(String[] args) {

   Scanner scan = new Scanner(System.in);

   System.out.print("Enter low: ");

   int low = scan.nextInt();

   System.out.print("Enter high: ");

   int high  = scan.nextInt();

   scan.close();

   int rndnumbers[] = new int[10];

   Random r = new Random();

   for(int i=0; i<rndnumbers.length; i++) {

     rndnumbers[i] = r.nextInt(high-low+1) + low;

   }

   for(int i=0; i<rndnumbers.length; i++) {

     System.out.printf("%d: %d\n", i, rndnumbers[i]);

   }

 }

}

4 0
2 years ago
in a particular factory, a team leader is an hourly paid production worker who leads a small team. in addition to hourly pay, te
malfutka [58]

Facilitate team development for successful project completion. Through coaching and mentoring, provide teammates with technical leadership.

Establishing best practices and habits will help the team maintain high standards for the quality of its software. Identify and promote the team's potential development and improvement areas.

#include<iostream>

using namespace std;

/*C++ Function to print leaders in an array */

void printLeaders(int arr[], int size)

{

  for (int i = 0; i < size; i++)

   {

       int j;

       for (j = i+1; j < size; j++)

       {

           if (arr[i] <=arr[j])

               break;

       }  

       if (j == size) // the loop didn't break

           cout << arr[i] << " ";

 }

}

/* Driver program to test above function */

int main()

{

   int arr[] = {16, 17, 4, 3, 5, 2};

   int n = sizeof(arr)/sizeof(arr[0]);

   printLeaders(arr, n);

   return 0;

}

Learn more about Development here-

brainly.com/question/28011228

#SPJ4

7 0
1 year ago
What does obsolete mean?
Alex
No longer produced or used; out of date.
8 0
2 years ago
Read 2 more answers
How do I type fast?<br><br> Give me an actual answer...
Ugo [173]
Practice!
And a good keyboard I recommend mechanical key boards
But the best way to improving your WPM is definitely practice one way you can practice is playing typeracer it’s pretty fun way

Hope this helps!
Brainliest is much appreciated!
7 0
2 years ago
Read 2 more answers
What are the steps for inserting an internal link?
julia-pushkina [17]

Answer:

=

Worksheet

Ctrl + Enter

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • What is the force generated by a rocket motor to propel a spacecraft forward?
    14·1 answer
  • What is 1-7? Plz help!!!
    15·1 answer
  • What is a central location that houses Joint Information System (JIS) operations and where public information staff perform publ
    6·1 answer
  • Microsoft words spell checker
    9·1 answer
  • PLS HELP ILL GIVE BRAINLY- (enter the answer) Microsoft _________ is an example of a desktop publishing software
    13·2 answers
  • Explain the integer and float datatypes with example.<br><br>​
    11·1 answer
  • Practising some questions for board exams for class 12 python,pls help with detailed answer
    14·1 answer
  • Help me please. I dont really understand this.
    12·2 answers
  • Why is it important to prepare the farm resources before you start working? explain​
    14·1 answer
  • Question 5 / 15
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!