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
Lorico [155]
3 years ago
12

#Write a function called "scramble" that accepts a string #as an argument and returns a new string. The new string #should start

with the last half of the original string #and end with the first half. # #If the length of the string is odd, split the string #at the floor of the length / 2 (in other words, the second #half is the longer half). # #For example: # scramble("abcd") -> "cdab" # screamble("abcde") -> "cdeab" # scramble("railroad")) -> "roadrail" # scramble("fireworks")) -> "worksfire"
Computers and Technology
1 answer:
mojhsa [17]3 years ago
8 0

Answer:

def scramble(s):

   if len(s) % 2 == 1:

       index = int(len(s)//2)

   else:

       index = int(len(s)/2)

   

   return s[index:] + s[:index]

Explanation:

Create a function called scramble that takes one parameter, s

Check the length of the s using len function. If the length is odd, set the index as the floor of the length/2. Otherwise, set the index as length/2. Use index value to slice the s as two halves

Return the second half of the s and the second half of the s using slice notation (s[index:] represents the characters from half of the s to the end, s[:index] represents the characters from begining to the half of the s)

You might be interested in
Write a function (named n_pointed_star) to make the turtle draw an n-pointed star. The function should return nothing, and accep
Andreyy89

Answer:

import sys

import turtle

import random

def n_pointed_star(total_points):

if total_points <= 4:

 raise ValueError('Not enough total_points')

area = 150

for coprime in range(total_points//2, 1, -1):

 if greatest_common_divisor(total_points, coprime) == 1:

  start = turtle.position()

  for _ in range(total_points):

   turtle.forward(area)

   turtle.left(360.0 / total_points * coprime)

  turtle.setposition(start)

  return

def greatest_common_divisor(a, b):

while b != 0:

 a, b = b, a % b

return a

   

turtle.reset()

n_pointed_star(5)

Explanation:

  • Inside the n_pointed_star function, check whether the total no. of points are less than or equal to 4 and then throw an exception.
  • Loop through the total_points variable and check whether the result  from greatest_common_divisor is equal to 1 or not and then set the starting position of turtle and move it.
  • Create the greatest_common_divisor which takes two parameters a and b to find the GCD.
  • Finally reset the turtle and call the n_pointed_star function.
8 0
3 years ago
After installing the second hard drive . what two tasks need to be done and what do they do?
Sunny_sXe [5.5K]
Create a partition using the Disk Management program and format the hard drive.

The first point will allow the hard drive to be put to use, and the second point will clear the hard drive completely so it's ready for use. 
3 0
3 years ago
Anybody plays mine craft
GuDViN [60]
Want to avoid giant mushrooms than stay away from dark oak and mooshroom biomes
5 0
3 years ago
Read 2 more answers
Match each command group under Picture Tools to the appropriate tasks.
FrozenT [24]

Answer:

look at the attachment for correct answers.

6 0
3 years ago
Which is NOT an event associated with the beginning of the internet
sammy [17]

Answer:

when Gandhi was born he had nothing to do with the internet. nothing can connect Gandhi to the internet.

Explanation:

Gandhi was an Indian activist who was the leader of the Indian independence movement against British colonial rule. therefore, there is no connection.

8 0
3 years ago
Other questions:
  • Which step of creating a financial budget involves listing the payroll, rental, and utility costs?
    10·2 answers
  • Gabe wants to move text from one document to another document he should __
    5·2 answers
  • If you have a charger that’s not from Apple, then could that damaged your iPhone or not?
    5·1 answer
  • Signing up for an IT course where others set the learning goals is an example of what kind of learning?
    10·1 answer
  • Calling all technology geeks— whenever I try to take a video; the video becomes muted and the sound button looks like this. Does
    15·1 answer
  • Create an array named itemDescription containing the following item descriptions:
    15·1 answer
  • Type size in a textbook may be used to indicate the relative importance of ideas.
    9·2 answers
  • If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of s
    12·1 answer
  • You receive an email that appears to legitimately be from your Bank. The email indicates the need for verification of your infor
    15·2 answers
  • Meera has created a small program in Python. She wants to store elements of the same data type in an organized
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!