Skip to main content

Section 7.16 Write Code Questions

Activity 7.16.1.

Fix line 2 so that it prints β€œHi” instead of β€œhi”.
Solution.
Fix line 2 so that it prints β€œHi” instead of β€œhi”.

Activity 7.16.2.

Loading a select question (grading type: first)...

Activity 7.16.3.

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

Activity 7.16.4.

Loading a select question (grading type: first)...

Activity 7.16.5.

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.
Solution.
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.

Activity 7.16.6.

Loading a select question (grading type: first)...

Activity 7.16.7.

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

Activity 7.16.8.

Loading a select question (grading type: first)...

Activity 7.16.9.

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

Activity 7.16.10.

Loading a select question (grading type: first)...

You have attempted of activities on this page.