Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*using python 1. Write a function flipside(s) that takes a string input s and returns a string whose first half is s's second half and

image text in transcribed*using python

1. Write a function flipside(s) that takes a string input s and returns a string whose first half is s's second half and whose second half is s's first half. If len(s) (the length of s) is odd, the first half of the input string should have one fewer character than the second half, and thus the second half of the output string will be one character shorter in such cases. For example: >>flipside('homework workhome >>>print(flipside('carpets) petscar Hint: We strongly recommend computing len(s)//2 (using the integer- division operator //) and storing the result in an appropriately named variable. You will need to use that value twice in your function, and using the variable in both places with save you from recomputing it. 2. Write a function adjust(s, length) that takes as inputs a string s and an integer length, and that returns a string in which the value of s has been adjusted as necessary to produce a string with the specified length. If s is too short, the value that is returned should be "padded" with spaces on the left-hand side: >>>adjust('alien', 6) alien' >>>adjust(' compute', 10) # pad with 1 space to get a length compute # pad with 3 spaces to get a lengt If s is either the correct length or too long, the value that is returned should consist of the first length characters of s: >adjust('alien', 4) alie >>>print(adjust(' compute', 7)) compute # return the first 4 characters # return the first 7 characters

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

Students also viewed these Databases questions