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
Judy forgot where she saved a certain file on her computer. Therefor, she searches for all files with a jpg file extension. Whic
Keith_Richards [23]
What are these files anyways
6 0
3 years ago
Read 2 more answers
Which of the following statements about Java Class Libraries is false: a. Java class libraries consist of classes that consist o
blondinia [14]

Answer:

Statement D is false

D. Java class libraries are not portable = FALSE

Explanation:

Because java class library are portable and JVM (java virtual machine) makes java class library and other java codes portable and platform independent and JVM act as a OS or imaginary CPU for that code.

8 0
3 years ago
The most basic software required for an online course where writing is involved is:
Andrej [43]
The annswer is word processing.
7 0
3 years ago
How does Google work, why does it work that way?
Oxana [17]

Answer:

Google uses automated programs called spiders or crawlers, just like most search engines, to help generate its search results. Google has a large index of keywords that help determine search results. ... Google uses a trademarked algorithm called PageRank, which assigns each Web page a relevancy score.

8 0
3 years ago
Read 2 more answers
What does obsolete mean?
Alex
No longer produced or used; out of date.
8 0
3 years ago
Read 2 more answers
Other questions:
  • A person painting his house dumps the unused paint on the ground. Which of the following resources will this most likely pollute
    14·1 answer
  • The first computer (the eniac was how big
    8·1 answer
  • You should structure the<br> first before you search for a relevant picture.
    11·1 answer
  • In Modern operating system, the __ feature has dramatically improved user productivity.
    11·1 answer
  • . public members are accessible from ________________ where the object is visible
    9·1 answer
  • I need help with workplace safety systems please help
    10·1 answer
  • Which job role requires you to create user guides for computer products and services?
    11·1 answer
  • Braxton is writing a program to design t-shirts. Which of the following correctly sets an attribute for color?
    7·1 answer
  • Write a program that uses a while loop to calculate and print the multiples of 3 from 3 to 21. Your program should print each nu
    11·1 answer
  • Sistem komponen mekanikal yang terdapat pada sebuah basikal?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!