Input
Introduction
Typically, programs take input from a user, process this input and give the user output.
input function
The input() function takes input from your console. It reads the input and converts it to a string.
Variable Roles
Changing the data type of the input
Function | Converts | Example |
int() | converts to an integer | num = int(input("Give me an integer: ")) |
float() | converts to a float | num = float(input("Give me a float: ")) |
When using the input function, think about about what data type you want.
A common mistake is not matching the number of open parenthesis and closed parenthesis.
Example
Write a program that prompts for two numbers. Print the sum, difference, product, and quotient of those numbers. In addition, print the result of integer division and the modulus operator of those numbers.
example1.py
Last updated