In python PartA Write a program that accepts as input a sent

In python:

PartA: Write a program that accepts as input a sentence from the user in which all of the words are run together but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter.

Objectives Students will be able 1. to access string elements by index operator 2. to search for simple pattern in strings Specification Part A (50%): write a program that accepts as input a sentence from the user in which all of the words are run together but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example the string \"GoDownAndEatBreakfast\" would be converted to \"Go Down And Eat Breakfast.\" Define a function for this section called partA) in your code for us to test this part of the assignment. Part B (50%): write a program that lets the user enter a string and displays the character that appears most frequently in the string. Define a function for this section called partB) in your code.

Solution

Part A


def PartA( string ):
n = 0
result = \"\"
for c in string:
if c.isupper() and n > 0:
result += \" \"
result += c.lower()
else:
result += c
n += 1
print result

user_variable = raw_input(\"Enter a sentence with run together words where, first alphabet of the word should be uppercase: \")
PartA( user_variable );

Part B


def PartB(variable):
import collections
print\"Most frequently occuring Character is: \",collections.Counter(variable).most_common(1)[0]

user_variable = raw_input(\"Enter a string: \")
PartB(user_variable)

In python: PartA: Write a program that accepts as input a sentence from the user in which all of the words are run together but the first character of each word

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site