Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help writing some Python 3+ programs. The instructions are: 1) Write a function rotate(s,n) that has one string parameter s followed by

Hello, I need help writing some Python 3+ programs. The instructions are:

1) Write a function rotate(s,n) that has one string parameter s followed by a positive integer parameter n. It returns a rotated string such that the last n characters have been moved to the beginning. If the string is empty or a single character, the function should simply return the string unchanged. Assume that n is less than or equal to the length of s and that n is a positive intger. For example: rotate('abcdefgh',3) returns 'fghabcde'

2) Write a function named digit_count that takes one parameter that is a number (int or float) and returns a count of even digits, a count of odd digits, and a count of zeros that are to the left of the decimal point. Return the three counts in that order: even_count, odd_count, zero_count. Be careful of the edge case where the number starts with a decimal pointconversion of such a number to a string places a zero before the decimal point. See correct behavior in the final test case below. For example: digit_count(1234567890123) returns (5, 7, 1) digit_count(123400.345) returns (2, 2, 2) print(digit_count(123.)) returns (1, 2, 0) print(digit_count(.123)) returns (0, 0, 0)

3) String has a method s.isdigit() that returns True if string s contains only digits and False otherwise, i.e. s is a string that represents an integer. Write a function named float_check that takes one parameter that is a string and returns True if the string represents a float and False otherwise. For the purpose of this function we define a float to be a string of digits that has at most one decimal point. Note that under this definition an integer argument will return True. Remember edge cases such as 45. or .45; both should return True.

For example: float_check('1234') returns True

float_check('123.45') returns True

float_check('123.45.67') returns False

float_check('34e46') returns False

float_check('.45') returns True

float_check('45.') returns True

float_check('45..') returns False

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

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions