Lab 8.1 - Casting

In Your Lab Worksheet

Predict what the following inputs will result in

Once you have filled in the Prediction column, check your answers in interactive mode and write the actual result.

Input

float('1')

str(1 + '2')

str('2')

int('abc')

int(float('1.6'))

float(int(1.6))

str(float(1))

In Your Editor (main.py)

  1. Create a program which will take in an input and print out that input divided by 2.

  2. Change one line of that program to return only whole numbers.

Bonus

Make your program have two modes: an integer mode and a float mode.

  • Add another input to ask which mode the user wants to use.

  • If the user asks for integer mode, then print out integers as the result of your division. Otherwise print out floating-point values (decimals).

  • Feel free to research Python3 documentation about division and if-else statements.

Last updated

Was this helpful?