forked from midudev/curso-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_input.py
More file actions
26 lines (21 loc) · 989 Bytes
/
05_input.py
File metadata and controls
26 lines (21 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
###
# 05 - Entrada de usuario (input()) - Versión simplificada
# La función input() permite obtener datos del usuario a través de la consola.
###
from os import system
if system("clear") != 0: system("cls")
# Para obtener datos del usuario se usa la función input()
# La función input() recibe un mensaje que se muestra al usuario
# y devuelve el valor introducido por el usuario
nombre = input("Hola, ¿cómo te llamas?\n")
print(f"Hola {nombre}, encantado de conocerte")
# Ten en cuenta que la función input() devuelve un string
# Así que si queremos obtener un número se debe convertir el string a un número
age = input("¿Cuántos años tienes?\n")
age = int(age)
print(f"Tienes {age} años")
# La función input() también puede devolver múltiples valores
# Para hacerlo, el usuario debe separar los valores con una coma
print("Obtener múltiples valores a la vez")
country, city = input("¿En qué país y ciudad vives?\n").split()
print(f"Vives en {country}, {city}")