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
ehidna [41]
2 years ago
12

Assume the variable myWord references a string. Write a statement that uses a slicing

Computers and Technology
1 answer:
givi [52]2 years ago
3 0

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

You might be interested in
PushBullet is an app to talk with people. Look it up and let me know u got it.
lisov135 [29]

Answer:

k

Explanation:

5 0
3 years ago
Read 2 more answers
Multiple Select
s344n2d4d5 [400]

Since you wrote a program to compare the portion of drivers who were on the phone. The statements are true are option  2, 3, 4 and 5:

2. You could modify the program to allow the user to enter the data.

3. A different set of observations might result in a larger portion of male drivers being on the phone.

4. Even when confident that the mathematical calculations are correct, you still need to be careful about how you interpret the results.

5. It is important to test your program with a small enough set of data that you can know what the result should be.

<h3>What use does a driver program serve?</h3>

A computer software known as a driver, sometimes known as a device driver, that serves as a bridge between the operating system and a device such a disk drive, or keyboard. The device's collection of specific commands must be thoroughly understood by the driver.

In software, a driver offers a programming interface for managing and controlling particular lower-level interfaces that are frequently connected to a particular kind of hardware or other low-level service.

Therefore,  based on the fact that the code you have made is okay, you can make some a notes on what is good and not and then make adjustments.

Learn more about program drivers from

brainly.com/question/28027852

#SPJ1

4 0
2 years ago
A computer uses a memory unit with 256k words of 32 bits each. A bina.ry
iogann1982 [59]

Answer:

Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

4 0
3 years ago
(in python)Write a program that takes a date as input and outputs the date's season. The input is a string to represent the mont
alexgriva [62]

Answer:

free points boi

Explanation:

3 0
3 years ago
Deep water can ____.
Hoochie [10]
D. Stall your vehicle
5 0
3 years ago
Read 2 more answers
Other questions:
  • When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
    11·1 answer
  • Who was responsible for unleashing the melissa computer virus
    15·1 answer
  • You are setting up a RAID system in a server designed for optimum fault tolerance, accuracy, and minimal downtime. Which HDD is
    7·1 answer
  • The component of a computer that provides the cpu with a working storage area for program instructions and data is called the __
    10·2 answers
  • Handouts are pages of your presentation that you print and distribute to your audience
    10·1 answer
  • Which formatting option(s) can be set for Conditional Formatting rules?
    8·2 answers
  • What is the full form of HTML?​
    8·2 answers
  • What is open source software? ​
    8·1 answer
  • Mechanisms that can be used to rescue accident victims
    11·1 answer
  • Question # 9
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!