replit

Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.

CodeSports

4-4-Make

Students are tasked to create their own code to perform a task.

Task


  • Make the user enter the length and width of a rectangle
  • Calculate the area of the rectangle
  • Output the area of the user’s rectangle to the screen

Learning Goals


Be able to read, understand, trace, adapt and create Python code using selection that:

  • Perform simple operations such as addition (+), subtraction (-), multiplication (*), and division (/) on fixed numbers
  • Perform simple operations on numbers stored in variables
  • Convert strings into integers
  • Gets number input from user and use it within calculations

Division Differences


If one / is used for division, the result will be a decimal, known as a float. If two // are used for division, the result will be a whole number, known as an integer (or int for short).

Casting


Input from the user in Python code is usually a string(text), but calculations required an integer(whole number) or a float(decimal number). Casting is the act of changing the data type of a variable to match a need.

Input Methods


To save the user’s inputted number as a whole number in a variable, use **int(input(“Ask user to enter something -> “))

To save the variable as a decimal number, use **float(input(“Ask user to enter something -> “))

Slide Deck


The link to the slide deck for this topic can be found here:

https://docs.google.com/presentation/d/1choFBbf7jyjNm-h37Z4Qyo1xOVVTj0W6mj6PCLRjbYw/edit?usp=sharing

Help! My Code Does Not Work!


When you run into an error with your code, ensure you have checked the following:

  • The variable name you have declared is the exact same throughout the program
  • You have used a single = to assign variables
  • You have used the correct operators for:
    • + addition
      
    • - subtraction
      
    • * multiplication
      
    • / float division
      
    • // integer division
      
  • You have placed brackets around input()

Hints