Chapter 4 Exercises¶
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”.
Fix the syntax errors so it prints “My name is Sam and I am 12 years old.”
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.”
Using the variables given, modify the print statement to print
"A car travelling at 70 mph takes 2 hours to go 140 miles."
There are 3 syntax errors in the following code. Fix it to print correctly without errors. It will print your name and age.
Fix the syntax errors so that the code prints “The apple costs $5”.
Modify line 6 to print: “The number of miles you can drive on 25 dollars is 273.97260274.”
Complete the code so that only “giant alligator” is printed.
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.”
Fix the code so that only “meow” is printed.
Combine lines 4 and 5 in the code below to print: “270 is 4.0 hours and 30 minutes.”
Complete the code on lines 3 and 4 so that it prints “2” and then “22”.
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.”
Fix line 2 so that it prints “Hi” instead of “hi”.
Write code to get the name of a color from the user using the
inputfunction. Next convert the name of the color to all lowercase letters and print it.
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.
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.”
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.
Write code below to get at least 3 values from the user using the
inputfunction and output a mad lib (which will use the input to tell a silly story).
Write code that gets user input and print a string that states their input in all lowercase and gives the length of their string.