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

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

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

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

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

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

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

  8. Complete the code so that only “B” is printed, then change it so that only “C” is printed.

  9. Complete the code so that only “B” is printed, then change it so that only “C” is printed.

  10. Complete the code so that only “giant alligator” is printed.

  11. 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.”

  12. Fix the code so that only “meow” is printed.

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

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

  15. 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.”

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

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

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

  19. 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.”

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

  21. 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).

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

Next Section - Chapter 5 - Names for Turtles