2nd Semester Intro to Computer Science

Lab 2.01 - Casting

In your notebook

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 Prediction Result
float('1')    
str(1 + '2')    
str('2')    
int('abc')    
int(float('1.6'))    
float(int(1.6))    
str(float(1))    

In your Console

  1. Create a program which will take in an input and print out that input divided by 2.
  2. Alter 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 is in integer mode print out integers, otherwise print out float. Feel free to research Python docs (This is a concept covered in Snap)

Edit this page Report an issue