Python - Lesson 2.1 Input and Output
Автор: Culer Damage
Загружено: 2025-11-01
Просмотров: 1
This lesson focused on how to make your Python programs interactive by exchanging data with the user.
1. Output: Showing Information
• We use the print() function to display text, numbers, or the values of variables to the console.
• Key Controls:
◦ The sep= argument changes what separates multiple items (default is a space).
◦ The end= argument changes what appears at the end of the print statement (default is a newline).
2. Input: Getting Information
• We use the input() function to pause the program and ask the user for data.
• The function displays a prompt and waits for the user to press Enter.
• The data the user types is always returned as a string (str), regardless of what it looks like.
◦ Example: If the user types 10, your program receives the string "10".
3. Type Conversion (Casting)
• Because input() returns a string, you must convert (cast) it if you need to perform calculations.
• Use the int() function to convert a string to a whole number (integer).
• Use the float() function to convert a string to a number with a decimal point (float).
Action Item: Time to Practice!
The best way to master I/O is to use it.
Now, please complete the three practice challenges below. If you encounter errors (especially related to math), check your type conversion!
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: