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
vaieri [72.5K]
3 years ago
14

Modify the list according to the following: append the smallest value at the end of the list when all numbers in the list are ne

gative, append the largest value at the end of the list when all numbers are greater than or equal t。О. Leave the list untouched otherwise. Sample Inputs/Outputs: Example Call: list_min_max_same ([-1, -99,-81) Expected Result: -1,-99, -8,-99] Example input: list_min_max_same ([1,99,8]) Expected Result: [1,99,8,99 Example input: list_min_max_same ([-1,99,-81)
Computers and Technology
1 answer:
ddd [48]3 years ago
3 0

Answer:

The solution code is written in Python 3:

  1. def modifyList(listNumber):
  2.    posCount = 0
  3.    negCount = 0
  4.    for x in listNumber:
  5.        if x > 0:
  6.            posCount += 1
  7.        else:
  8.            negCount += 1
  9.    
  10.    if(posCount == len(listNumber)):
  11.        listNumber.append(max(listNumber))
  12.    
  13.    if(negCount == len(listNumber)):
  14.        listNumber.append(min(listNumber))
  15.    
  16.    print(listNumber)
  17. modifyList([-1,-99,-81])
  18. modifyList([1,99,8])
  19. modifyList([-1,99,-81])

Explanation:

The key step to solve this problem is to define two variables, posCount and negCount, to track the number of positive value and negative value from the input list (Line 2 - 3).

To track the posCount and negCount, we can traverse through the for-loop and create if else statement to check if the current number x is bigger than 0 then increment posCount by 1 otherwise increment negCount (Line 5- 9).

If all number in the list are positive, the posCount should be equal to the length of the input list and the same rule is applied to negCount. If one of them happens, the listNumber will append either the maximum number (Line 11 -12) or append the minimum number (Line 14-15).

If both posCount and negCount are not equal to the list length, the block of code Line 11 -15 will be skipped.

At last we can print the listNumber (Line 17).

If we test our function using the three sets of input list, we shall get the following results:

[-1, -99, -81, -99]

[1, 99, 8, 99]

[-1, 99, -81]

You might be interested in
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county s
iVinArrow [24]

Answer:

purchase_amount = float(input("Enter the amount of a purchase: "))

state_sales_tax = purchase_amount * 0.05

country_sales_tax = purchase_amount * 0.025

print("The amount of the purchase is " + str(purchase_amount))

print("The state sales tax is " + str(state_sales_tax))

print("The county sales tax is " + str(country_sales_tax))

print("The total sales tax is " + str(state_sales_tax + country_sales_tax))

print("The total of the sale is " + str(purchase_amount + state_sales_tax + country_sales_tax))

Explanation:

*The code is in Python.

Ask the user to enter purchase amount

Calculate the state sales tax, multiply purchase amount by 0.05

Calculate the county sales tax, multiply purchase amount by 0.025

Calculate the total sales tax, sum the state sales tax and county sales tax

Print the amount of the purchase, state sales tax, county sales tax, total sales tax and  total of the sale

7 0
3 years ago
The basic form of backup used in magnetic tape operations is called
Harrizon [31]
Answer is the son-father-grandfather concept. Good luck
5 0
3 years ago
You administer a Microsoft SQL Server database that supports a banking transaction management application. You need to retrieve
dusya [7]

Answer:

A, B

Explanation:

A. selects accountholder's ids and check them with those who don't have cities in BranchMaster table.

B. We can use both <em>NOT IN</em><em> </em> as well as <> operator for comparison so it selects accountholder's ids which are not in all of those account holders who have cities in BranchMaster.

5 0
3 years ago
Create a Quadrilateral, Oval, Triangle, Polygon class that are all extended from an abstract Shape class (given below). Then ext
Lostsunrise [7]

Answer:

Shapes.java

public abstract class Shapes {

}

Triangle.java

public abstract class Triangle extends Shapes {

}

IsoscelesTriangle.java

public class IsoscelesTriangle extends Triangle {

double side1;

double side2;

public double getSide1() {

return side1;

}

public void setSide1(double side1) {

this.side1 = side1;

}

public double getSide2() {

return side2;

}

public void setSide2(double side2) {

this.side2 = side2;

}

public IsoscelesTriangle(double side1, double side2) {

super();

this.side1 = side1;

this.side2 = side2;

}

public double perimeter()

{

return 2*side1+side2;

}

public double area()

{

return side1*side2/2;

}

}

EquilateralTriangle.java

public class EquilateralTriangle extends Triangle {

double side;

public EquilateralTriangle(double side) {

super();

this.side = side;

}

public double getSide() {

return side;

}

public void setSide(double side) {

this.side = side;

}

public double perimeter()

{

return 3*side;

}

public double area()

{

return 1.73205*side*side/4;

}

}

Quadrilateral.java

public abstract class Quadrilateral extends Shapes {

}

Rectangle.java

public class Rectangle extends Quadrilateral {

double length;

double breadth;

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getBreadth() {

return breadth;

}

public void setBreadth(double breadth) {

this.breadth = breadth;

}

public Rectangle(double length, double breadth) {

super();

this.length = length;

this.breadth = breadth;

}

public double perimeter()

{

return 2*(length+breadth);

}

public double area()

{

return length*breadth;

}

}

Square.java

public class Square extends Quadrilateral {

double side;

public Square(double side) {

super();

this.side = side;

}

public double getSide() {

return side;

}

public void setSide(double side) {

this.side = side;

}

public double perimeter()

{

return 4*side;

}

public double area()

{

return side*side;

}

}

Rhombus.java

public class Rhombus extends Quadrilateral {

double length;

double breadth;

public Rhombus(double length, double breadth) {

super();

this.length = length;

this.breadth = breadth;

}

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getBreadth() {

return breadth;

}

public void setBreadth(double breadth) {

this.breadth = breadth;

}

public double perimeter()

{

return 2*(length+breadth);

}

public double area()

{

return length*breadth/2;

}

}

Test.java

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

System.out.println("Enter your choice");

System.out.println("1. Create IsoscelesTriangle ");

System.out.println("2. Create EquilateralTriangle");

System.out.println("3. Create Rectangle");

System.out.println("4. Create Square");

System.out.println("5. Create Rhombus");

System.out.println("6. Create Circle");

int choice=sc.nextInt();

switch(choice)

{

case 1:

System.out.println("Enter two sides of triangle");

double side1=sc.nextDouble();

double side2=sc.nextDouble();

IsoscelesTriangle isosceles=new IsoscelesTriangle(side1, side2);

System.out.println("Area of the triangle is "+isosceles.area());

System.out.println("Perimeter of the triangle is "+ isosceles.perimeter());

break;

case 2:

System.out.println("Enter side of the triangle");

double side=sc.nextDouble();

EquilateralTriangle equilateralTriangle=new EquilateralTriangle(side);

System.out.println("Area of the triangle is "+equilateralTriangle.area());

System.out.println("Perimeter of the triangle is "+ equilateralTriangle.perimeter());

break;

case 3:

System.out.println("Enter length and breadth");

double length=sc.nextDouble();

double breadth=sc.nextDouble();

Rectangle rectangle =new Rectangle(length, breadth);

System.out.println("Area of rectangle is "+rectangle.area());

System.out.println("Perimeter of the rectangle is "+rectangle.perimeter());

break;

case 4:

System.out.println("Enter side of the square");

double squareside=sc.nextDouble();

Square square=new Square(squareside);

System.out.println("area of the square is "+square.area());

System.out.println("Perimeter of the square is "+square.perimeter());

break;

case 5:

System.out.println("Enter length and breadth of rhombus");

double rlength=sc.nextDouble();

double rbreadth=sc.nextDouble();

Rhombus rhombus=new Rhombus(rlength, rbreadth);

System.out.println("area of the rhombus is "+rhombus.area());

System.out.println("Perimeter of the rhombus is "+rhombus.perimeter());

break;

case 6:

System.out.println("Enter radius of circle");

double radius=sc.nextDouble();

Circle circle=new Circle(radius);

System.out.println("area of the circle is "+circle.area());

System.out.println("Perimeter of the circle is "+circle.perimeter());

break;

}

}

}

8 0
3 years ago
What standard tcp port does the bgp service operate on?
Yanka [14]

Answer:

BGP neighbors are defined by an IP address. BGP uses TCP port 179 to communicate with other routers.

3 0
2 years ago
Other questions:
  • "Create a Python program named detect_column_level_data_entry_errors. When complete, you will run this program to produce a diag
    11·1 answer
  • 8.5 question 2 edhesive
    11·1 answer
  • QUESTION 16
    14·1 answer
  • Using truth table, prove that:<br><br> (A + B). C = (A . C)+ (B .C) ?
    7·1 answer
  • What effect on total current flow will a shorted series component have in a series-parallel circuit?
    8·1 answer
  • The process of combining rows and columns in a table is called _____.
    8·1 answer
  • Software is the word for:
    15·1 answer
  • Which graph is the solution to the system 2x – 3 and y &lt; 2x + 4?
    5·2 answers
  • 4. Write technical term for the following statements
    15·2 answers
  • A(n) _____ exists when there are functional dependencies such that XY is functionally dependent on WZ, X is functionally depende
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!