2.17. Write Code Questions

  1. There are 3 syntax errors in the following code. Fix it to print correctly without errors. It will print, “Her name is Molly and her favorite food is tuna”.

    There are 3 syntax errors in the following code. Fix it to print correctly without errors. It will print, “Her name is Molly and her favorite food is tuna”.

  2. Let’s say that apples are $0.40 apiece, and pears are $0.65 apiece. Modify the program below to calculate the total cost of 4 apples and 3 pears

  3. Take the phrase: twinkle twinkle little star. Store each word in a separate variable, then print out the sentence on one line using print.

    Take the phrase: twinkle twinkle little star. Store each word in a separate variable, then print out the sentence on one line using print.

  4. Add parentheses to the following code so that the total equals 40.

  5. Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off. Using the ``int()`` function and modulus operator ``%`` could come in handy!

    Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off. Using the ``int()`` function and modulus operator ``%`` could come in handy!

  6. Assume that you have 24 slices of pizza and 7 people that are going to share it. There’s been some arguments among your friends, so you’ve decided to only give people whole slices. Your pet dog Andy loves pizza. Write a Python expression with the modulus operator that calculates how many pizza slices will be left over for your dog after serving just whole slices to 7 people. Assign the result of that expression to forAndy.

  7. Write a program that will convert inches to feet from user input. Reminder: there are 12 inches in a foot.

    Write a program that will convert inches to feet from user input. Reminder: there are 12 inches in a foot.

  8. Write a program that will convert feet to inches from user input. Reminder: there are 12 inches in a foot.

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

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

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

You have attempted of activities on this page