Read the string "I am James Bond" and assign it to a variable a. Count the length of string. Count the occournace of letter ‘B” Count the total number of characters without the space in the above string. Hint: use the len(a) function to identify the length.           a.count(‘B’) to identify the occurance             a.count(‘ ’) to find out the space. 2.Convert the string "I am James Bond" to all uppercase and lowercase characters. Hint: use the a.upper() and a.lower() Split the string "I am James Bond". What is the type of output? Hint: use the split() function. 3. print(type(a.split())) 4. Create a new variable a1, and assign “he , is, a, good, boy”. Split based on the “,” delimited Split the string to the maximum of 0, 1, and 2 numbers. What do you observe? Hint: General formula is str.split(separator, maxsplit)   Use the a1.split(',') . a1.split(',' , 0)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question
  1. Read the string "I am James Bond" and assign it to a variable a.
    1. Count the length of string.
    2. Count the occournace of letter ‘B”
    3. Count the total number of characters without the space in the above string.

Hint: use the len(a) function to identify the length.

          a.count(‘B’) to identify the occurance

            a.count(‘ ’) to find out the space.

2.Convert the string "I am James Bond" to all uppercase and lowercase characters.

Hint: use the a.upper() and a.lower()

  1. Split the string "I am James Bond".
    1. What is the type of output?

Hint: use the split() function.

3. print(type(a.split()))

4. Create a new variable a1, and assign “he , is, a, good, boy”.

    1. Split based on the “,” delimited
    2. Split the string to the maximum of 0, 1, and 2 numbers. What do you observe?
    3. Hint: General formula is str.split(separator, maxsplit)  

      1. Use the a1.split(',') .
      2. a1.split(',' , 0)
Expert Solution
Python Program

#1.
a = input()
#Count the length of string.
length = len(a)
print("Length:", length)
#Count the occournace of letter ‘B”
occ =  a.count('B')
print("Occurances of 'B':", occ)
#Count the total number of characters without the space in the above string.
sp =  a.count(' ')
print("Number of characters without the space:", (length - sp))
print()

#2.
#Convert the string "I am James Bond" to all uppercase and lowercase characters.
x = a.upper()
y = a.lower()
print(x)
print(y)
#Split the string "I am James Bond"
lst = a.split()
print(lst)
print()

#3.
print(type(a.split()))
print()

#4.
#Create a new variable a1, and assign “he , is, a, good, boy”.
a1 = "he , is, a, good, boy"
#Split based on the “,” delimited
x1 = a1.split(',')
print(x1)
#Split the string to the maximum of 0, 1, and 2 numbers.
j = a1.split(',' , 0)
k = a1.split(',' , 1)
l = a1.split(',' , 2)
print(j)
print(k)
print(l)

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage