7.16. Write-code questions

Fix line 2 so that it prints “Hi” instead of “hi”.

The capitalize() method returns a new string; it doesn’t modify the original because strings are immutable. As a result, you need to assign the value of s1.capitalize() to s1.

Fix line 2 so that it prints “Hi” instead of “hi”.

Loading a dynamic question ...
Selecting from: str-ex-meowacq, str-ex-meowansw

Write code to evaluate the length of the string “I like green eggs” and print it. It should print “The length is 17”.

You can use the len() method to find the length of a string.

Write code to evaluate the length of the string “I like green eggs” and print it. It should print “The length is 17”.

Loading a dynamic question ...
Selecting from: str-ex-countacq, str-ex-countansw

Take the following Python code that stores this string: string = "X-DSPAM-Confidence: 0.8475". Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number called num.

The float() function ignores whitespace, so you can begin the slice at the space character after the colon or at the 0 – your choice!

Take the following Python code that stores this string: string = "X-DSPAM-Confidence: 0.8475". Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number called num.

Loading a dynamic question ...
Selecting from: str-ex-ducksacq, str-ex-ducksansw

Write a function numDigits that will return the number of digits in an integer n.

Convert the integer to a string, then use the len() method.

Write a function numDigits that will return the number of digits in an integer n.

Loading a dynamic question ...
Selecting from: str-ex-nameacq, str-ex-nameansw

Write a program that asks a user for their name and from the input prints the first letter of their name in lowercase.

Use the input() function to get the user’s input, then use indexing and the lower() method to print the first letter of their name in lowercase.

Write a program that asks a user for their name and from the input prints the first letter of their name in lowercase.

Loading a dynamic question ...
Selecting from: str-ex-loweracq, str-ex-loweransw

You have attempted of activities on this page