Chapter 4 Exercises

  1. There are 3 syntax errors in the following code. Fix it to print correctly without errors. It will print, “Your name is Carly and your favorite color is red”.

    Show Comments
  2. Fix the syntax errors so it prints “My name is Sam and I am 12 years old.”

    Show Comments
  3. You will get an error if you try to run the following code. Fix the code to print correctly without errors. It should print, “Your name is Carly and your age is 5.”

    Show Comments
  4. Using the variables given, modify the print statement to print "A car travelling at 70 mph takes 2 hours to go 140 miles."

    Show Comments
  5. There are 3 syntax errors in the following code. Fix it to print correctly without errors. It will print your name and age.

    Show Comments
  6. Fix the syntax errors so that the code prints “The apple costs $5”.

    Show Comments
  7. Modify line 6 to print: “The number of miles you can drive on 25 dollars is 273.97260274.”

    Show Comments
  8. Complete the code so that only “giant alligator” is printed.

    Show Comments
  9. Modify line 6 to print: “You can order 40.0 wings when you have 5 people who can each spend 4 dollars and wings cost 0.5 each.”

    Show Comments
  10. Fix the code so that only “meow” is printed.

    Show Comments
  11. Combine lines 4 and 5 in the code below to print: “270 is 4.0 hours and 30 minutes.”

    Show Comments
  12. Complete the code on lines 3 and 4 so that it prints “2” and then “22”.

    Show Comments
  13. Complete the calculations on lines 2 and 4 and enter the items to be printed on line 5 to print the number of miles you can drive if you have a 10 gallon gas tank and are down to a quarter of a tank of gas and your car gets 32 miles per gallon. It should print: “You can go 80.0 miles.”

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

    Show Comments
  15. Write code to get the name of a color from the user using the input function. Next convert the name of the color to all lowercase letters and print it.

    Show Comments
  16. Write code to get the input of a user’s first name, then get only the first letter of their name, and print that letter lowercase.

    Show Comments
  17. Write the code below to calculate and print how many months it will take to save $200 if you earn $20 a week. It should print: “It will take 2.5 months to earn 200 if you make 20 dollars a week.”

    Show Comments
  18. Write code to print out the statement “Hi my name is Bob and I am 2” using only string methods or string slicing. You must get every part of the new string from the given strings.

    Show Comments
  19. Write code below to get at least 3 values from the user using the input function and output a mad lib (which will use the input to tell a silly story).

    Show Comments
  20. Write code that gets user input and print a string that states their input in all lowercase and gives the length of their string.

    Show Comments
Next Section - Exam Questions for Chapters 3 and 4