answer.
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
adoni [48]
2 years ago
5

Imagine you have a 10-character string stored in the variable myString. You want to pull out the first five characters. Which of

the following lines of code would successfully generate a slice of the 10-character string holding only the first five characters?
a. myString[5]
b. myString[:-5]
c. myString[0:6]
d. myString-15:-5]
e. myString[0:10:2]
Computers and Technology
1 answer:
Andre45 [30]2 years ago
6 0

Answer:

b. myString[:-5]

d. myString[-15:-5]

Explanation:

I believe you have a typo in d. It must be d. myString[-15:-5]

Slicing can be done:

myString[starting_index, stopping_index, step] (step is optional). If you do not specify the starting index, it will start from the 0 as in b. If you write a range that is not in the range, as in d, Python will replace it with either 0 or length of the string (In this case, it is replaced with 0 because the starting index must be smaller than stopping index)

a. myString[5] → This will give you the sixth character

b. myString[:-5] → This will give you the first five characters

c. myString[0:6] → This will give you the first six characters

d. myString-15:-5] → This will give you the first five characters

e. myString[0:10:2] → This will give you the first, third, fifth, seventh, and ninth characters

You might be interested in
Grabar microphone audio icon_person click each item to hear a list of vocabulary words from the lesson. then, record yourself sa
Vaselesa [24]

Because this is a on your own problem, it cannot be solved. You must speak to it after the person says something.

5 0
2 years ago
Read 2 more answers
Write a program that uses the Purchase class in 5.13. Set the prices to the following: Oranges: 10 for $2.99 Eggs: 12 for $1.69
Xelga [282]

Answer:

Explanation:

The following program is written in Java. Using the program code from Purchase class in 5.13 I created each one of the fruit objects. Then I set the price for each object using the setPrice method. Then I set the number of each fruit that I intended on buying with the setNumberBought method. Finally, I called each objects getTotalCost method to get the final price of each object which was all added to the totalCost instance variable. This instance variable was printed as the total cost of the bill at the end of the program. My code HIGHLIGHTED BELOW

//Entire code is in text file attached below.

//MY CODE HERE

       DecimalFormat df = new DecimalFormat("0.00");

       oranges.setPrice(10, 2.99);

       oranges.setNumberBought(2*12);

       eggs.setPrice(12, 1.69);

       eggs.setNumberBought(2*12);

       apples.setPrice(3, 1);

       apples.setNumberBought(20);

       watermelons.setPrice(1, 4.39);

       watermelons.setNumberBought(2);

       bagels.setPrice(6, 3.50);

       bagels.setNumberBought(12);

       totalCost = oranges.getTotalCost() + eggs.getTotalCost() + apples.getTotalCost() + watermelons.getTotalCost() + bagels.getTotalCost();

       System.out.println("Total Cost: $" + df.format(totalCost));

   }

}

5 0
2 years ago
He volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called pr
AfilCa [17]

Answer:

1) # function to print volume of a sphere

  def print_volume(radius):

   volume= (4/3)*3.14*radius*radius*radius

   print("Volume:{0}",volume)

print_volume(4.23)

print_volume(4.34)

print_volume(12.34)

Output:

Volume:{0} 316.8761018400001                                                                                                  

Volume:{0} 342.24536341333334                                                                                                  

Volume:{0} 7867.085384746666    

2) # area of square calculator

def print_area(length):

   area=length*length

   print("Area of Square{0}",area)

print_area(4.23)

print_area(4.34)

print_area(12.34)

Output:

Area of Square{0} 17.892900000000004                                                                                          

Area of Square{0} 18.8356                                                                                                      

Area of Square{0} 152.2756

Explanation:

We have created two functions, first to calculate the volume of a sphere. and second to calculate the area of a square. Remember pi=3.14.

5 0
2 years ago
A mistake programmers often make with loops is that they ____.
Soloha48 [4]

I think the best answer is D. Initialize the loop control variable prior to entering the loop body.

Please correct me if I'm wrong!! I'd be happy to fix it!! :)

4 0
2 years ago
Implement the function couple, which takes in two lists and returns a list that contains lists with i-th elements of two sequenc
In-s [12.5K]

Answer:

couple.py

def couple(s1,s2):

  newlist = []

  for i in range(len(s1)):

      newlist.append([s1[i],s2[i]])

  return newlist

s1=[1,2,3]

s2=[4,5,6]

print(couple(s1,s2))

enum.py

def couple(s1,s2):

  newlist = []

  for i in range(len(s1)):

      newlist.append([s1[i],s2[i]])

  return newlist

def enumerate(s,start=0):

  number_Array=[ i for i in range(start,start+len(s))]

  return couple(number_Array,s)

s=[6,1,'a']

print(enumerate(s))

print(enumerate('five',5))

Explanation:

7 0
2 years ago
Other questions:
  • A(n) ____ is an electronic device, operating under the control of instructions stored in its own memory, that can accept data, p
    14·1 answer
  • Which use case can be accomplished using a custom link? Choose 3 ans A. Navigate to a process to update the current record. B. N
    10·1 answer
  • Assume that a kernel is launched with 1000 thread blocks each of which has 512 threads. If a variable is declared as a shared me
    6·1 answer
  • A Class B network needs to be subnetted such that it supports 100 subnets and 100 hosts/ subnet. Which of the following answers
    8·1 answer
  • "online privacy alliance (opa) is an organization of companies dedicated to protecting online privacy. members of opa agree to c
    15·1 answer
  • Polygon transform (25 points). Write a library of static methods that performs various geometric transforms on polygons. Mathema
    12·1 answer
  • Design and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Y
    12·1 answer
  • Consider the following class declaration: public class Square { private double sideLength; public double getArea() { return side
    13·1 answer
  • What are the two atomic operations permissible on semaphores?
    8·1 answer
  • All of the following are true of functions except: Group of answer choices They define specific tasks that can be used at many p
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!