PRACTICE
INPUT EXERCISES


Exercises

  1. Some video games let you input information about your character, like below:

    Write a program to ask the user for their name, farm name, and favourite thing. Then, print a nice message back to the user using their inputs. For example, if I input “Ms. Fisher”, “Stardew”, and “eggs”, then you could display:
    Hi Ms. Fisher! I hope Stardew Farm has a plentiful egg season this year!

  2. Write a program that will calculate the area of a circle. The program should ask for the radius of the circle as input.
  3. You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.
    Write a program that asks the user for the age of the youngest and middle child, and outputs the age of the oldest child.
  4. Write a program that prompts for a decimal input, and prints out the decimal rounded to 2 decimal places.
  5. Write a program that asks the user for a number of hours, minutes, and seconds. The program should convert and print this measure to hours only. For example, if the user inputs 13 hours, 15 minutes, and 30 seconds, the program should return 13.26 hours.
  6. A soft drink company recently surveyed x of its customers and found that approximately y% of those surveyed purchased one or more energy drinks per week. Of those customers who purchased energy drinks, approximately z% of them prefer citrus-flavoured energy drinks.
    Write a program that asks the user for x, y, and z, and then outputs:
  1. Imagine that the days of the week were each given a number. For example, Sunday is 0, Monday is 1, Tuesday is 2, all the way to Saturday, which would be 6. Say you go on a wonderful holiday and you leave on day 3 (a Wednesday). You stay for 10 nights and return home on day 6 (Saturday).
    Write a program which asks the user for the starting day number of their vacation and the length of their stay. The program should print out the number of the day that the user would return on.