Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Write a program that prompts a user for an input string of length at least two and

prints the string with the


first half in upper case and the second half in lower case. If the length of the
string is odd, the "second
half" should be one character longer than the "first half".
Solution :

import math
length_str = input("Enter a string at least two.")

if(len(length_str) < 2) :
print("Please enter a string of at least two.")
length_str = input("Enter a string at least two.")

if len(length_str)%2 == 0:
middle = math.floor(len(length_str)/2)
first_piece = length_str[: middle].upper()
second_piece = length_str[middle :].lower()
print(first_piece + second_piece)

else :
middle = math.floor(len(length_str)/2)
first_piece = length_str[: middle].upper()
second_piece = length_str[middle : ].lower()
print(first_piece + second_piece)

Example Output :
Enter a string at least two.
aabbcdd

AABbcdd

You might also like