O GoConqr está de visual novo! Conte para nós o que você achou.

Módulo 2 de 13 · Texto

The input() function with an argument

David Khieu

The input() function with an argument

The input() function can do something else: it can prompt the user without any help from print().

We've modified our example a bit, look at the code:

anything = input("Tell me anything...")
print("Hmm...", anything, "...Really?")

Note:

  • the input()  function is invoked with one argument - it's a string containing a message
  • the message will be displayed on the console before the user is given an opportunity to enter anything
  • input() will do its job

The variant of th einput() invocation simplifies the code and makes it clearer. 

The result of the input() function 

We've said it already, but it must be unambiguously stated once again: the the result of the input() function is a string.

A string containing all the characters the user enters from the keyboard. It is not an integer or a float. 

This means that you mustn't use it as an argument of any arithmetic operation, e.g., you can't use this data to square it, divide it by anything, or divide anything by it. 

anything = input("Enter a number: ")
something = anything ** 2.0
print(anything, "to the power of 2 is", something)

Instruções

Para avançar no curso, envie uma tentativa deste quiz. Você pode enviá-la depois da última pergunta.

Ir para o módulo escolhido

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?