Skip to content

Python Programming · Week 3 notes

Inputs

Introduction to Python Inputs

Overview: Understanding Python Inputs

What are Inputs?

Inputs are simply data that the user provides to the computer. In Python, we use the input() function to get this data.

Key Concepts

  • Basic Input Function
    • The basic input function is: input()
    • Inputs are stored in variables for easy manipulation
    • Example usage:
      name = input()
  • Prompts
    • You can add a message inside the parentheses to tell the user what to type.
    • Example: input("Enter your name: ")

Quick check

  1. What is the function to get user input?

Understanding Inputs

This lesson covers how to convert input data types, particularly focusing on converting string inputs to integers and floats.

Understanding Input Data Types:

By default, the input() function returns a string. Even if the user types a number, Python treats it as text.

Converting Strings to Integers:

To convert a string input to an integer, use the int() function:

age = int(input("Enter your age: "))

Converting Strings to Floats:

To convert a string input to a decimal number (float), use the float() function:

price = float(input("Enter the price: "))

Quick check

  1. What is the basic Python function for getting user input?

  2. By default, what data type does input() return?