Python. Input data

11.1.1.5 organize keyboard inputs;

Python. Input data

The input() function allows the user to enter a value into the program. input() always returns a string value.

print('What is your name?')
name = input()
print('Hello,', name, '!')

When input() is executed, the program will stop and wait for user input. After entering data, the user should press Enter.

name = input('What is your name?')
print('Hello,', name , '!')

If you want to get an integer, then use the data type conversion functions.

For example, number = int(input())

Task 1. Write a simple program to add two integers a and b.

Variant 1

a = input()
b = input()
print(int(a) + int(b))

Variant 2

a = input()
b = input()
print(int(a) + int(b))

Variant 3

a = int(input())
b = int(input())
c = a + b
print(c)

Questions:

 

Exercises:

 

Exam questions:


 

Категория: Programming languages | Добавил: bzfar77 (09.09.2021)
Просмотров: 54 | Теги: Python, String, variable, Convert, Input | Рейтинг: 0.0/0
Всего комментариев: 0
avatar