Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python - 2. The Input Function

The input() function prints a prompt and returns text entered by the user, allowing input. It can pause a program until enter is pressed. The text returned is a string, so int() or float() must convert it for calculations. An example program prompts for a name and prints a greeting.

Uploaded by

luxiusgamer47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python - 2. The Input Function

The input() function prints a prompt and returns text entered by the user, allowing input. It can pause a program until enter is pressed. The text returned is a string, so int() or float() must convert it for calculations. An example program prompts for a name and prints a greeting.

Uploaded by

luxiusgamer47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The input() function

input(prompt)

The function input(prompt) prints the message 'prompt' to the screen and returns a line of
text typed by the user with the keyboard.

This function can be used to stop the program from running until the 'Enter' key or the
'Return' key is pressed.

Examples:

Notice how the number entered is a text string, so we cannot perform calculations with it. To
convert the text into a number you must use one of the following functions:

● int('') converts a text string to an integer (no decimals)


● float('') converts a text string to a floating point number.

Exercise:
Write a program that prompts for your name on the screen and then prints a personalized
greeting with your name.

You might also like