Skip to main content
Engineering LibreTexts

2.14: Variables, Expressions, and Statements (Exercises)

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Exercise 2: Write a program that uses input to prompt a user for their name and then welcomes them.

    Enter your name: Chuck
    Hello Chuck
    #Use this space to write and run your code

    Exercise 3: Write a program to prompt the user for hours and rate per hour to compute gross pay.

    Enter Hours: 35
    Enter Rate: 2.75
    Pay: 96.25

    We won't worry about making sure our pay has exactly two digits after the decimal place for now. If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places.

    #Use this space to write and run your code
    #Save this code for a later exercise!

    Exercise 4: Assume that we execute the following assignment statements:

    width = 17
    height = 12.0

    For each of the following expressions, write the value of the expression and the type (of the value of the expression).

    1. width//2
    2. width/2.0
    3. height/3
    4. 1 + 2 * 5
    #Use this space to check your answers

    Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.

    #Use this space to write and run your code

    1. In Python 2.0, this function was named raw_input.
    2. See for an extended description of the word "mnemonic".

    This page titled 2.14: Variables, Expressions, and Statements (Exercises) is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Chuck Severance.

    • Was this article helpful?