user interaction program

User input:

# Author :yanpengtao
# !/usr/bin/env python
# _*_coding:utf-8_*_

username = input("username:")
password = input("password:")
print(username, password)

The above program asks the user to enter a username and password, then prints the username and password

Formatted output:

 

The above has learned to format the output string, but many times we need to output digital, floating-point data, so what should we do? First try the following changes

After execution, it was found that an error was reported

When outputting, an error is reported according to the integer output, indicating that the input is not an integer data but a character data (the input data in python is a string type by default), which can also help us detect the data type of the data. Is it correct, and python is a mandatory type language, so you just need to cast the input when you type it.

No error will be reported after execution  

Here's another way to format the output

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887366&siteId=291194637