Day1_Python基础_8.用户输入

八、用户输入 

1
2
3
4
5
6
7
#!/usr/bin/env python
#_*_coding:utf-8_*_
 
 
#name = raw_input("What is your name?") #only on python 2.x
name = input("What is your name?")
print("Hello " + name )

输入密码时,如果想要不可见,需要利用getpass 模块中的 getpass方法,即:

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env python
# -*- coding: utf-8 -*-
  
import getpass
  
# 将用户输入的内容赋值给 name 变量
pwd = getpass.getpass("请输入密码:")
  
# 打印输入的内容
print(pwd)

# Author: George.Wang
# -*- coding: utf-8 -*-

# 注意在python2当中是raw_input,但既然我们选择了python3,那就放弃2里的特性吧。
# 额外注意的是,python2当中也有个input,这个input与变量有关,且用起来有各种各样的问题,不好用,所以在python3中去掉了。
#--------------------------基本input--------------------------------
"""
username = input("username:")
password = input("password:")
print (username,password)
"""

#---------------------格式化1输出input(内存块占用太多,不建议使用)-------------------------
"""
Name=input("name:")
Age=input("age:")
Job=input("job:")
Salary=input("salary:")
msg = '''
------Hi,'''+Name+''' Welcome to this system ------
Your name is: '''+Name+'''
Your age is: '''+Age+'''
Your job is: '''+Job+'''
Your salary is: '''+Salary+'''
'''
print(msg)
"""

#---------------------格式化2输出input-------------------------
"""
Name=input("name:")
Age=input("age:")
Job=input("job:")
Salary=input("salary:")
msg = '''
------Hi,%s Welcome to this system ------
Your name is: %s
Your age is: %s
Your job is: %s
Your salary is: %s
'''%(Name,Name,Age,Job,Salary)
print(msg)
"""

#---------------------格式化3输出input-------------------------
"""
Name=input("name:")
Age=int(input("age:"))     #integer
print(type(Age),type(str(Age)))   #默认情况下,python3全部为string类型,python是一种强类型字符语言
Job=input("job:")
Salary=int(input("salary:"))
msg = '''
------Hi,%s Welcome to this system ------
Your name is: %s
Your age is: %d
Your job is: %s
Your salary is: %d
'''%(Name,Name,Age,Job,Salary)
print(msg)
"""

#---------------------格式化4输出input-------------------------
"""
Name=input("name:")
Age=int(input("age:"))     #integer
print(type(Age),type(str(Age)))   #默认情况下,python3全部为string类型,python是一种强类型字符语言
Job=input("job:")
Salary=int(input("salary:"))
msg = '''
------Hi,{_name} Welcome to this system ------
Your name is: {_name}
Your age is: {_age}
Your job is: {_job}
Your salary is: {_salary}
''' .format(
    _name=Name,
    _age=Age,
    _job=Job,
    _salary=Salary,
)
print(msg)
"""
#---------------------格式化5输出input-------------------------

Name=input("name:")
Age=int(input("age:"))     #integer
print(type(Age),type(str(Age)))   #默认情况下,python3全部为string类型,python是一种强类型字符语言
Job=input("job:")
Salary=int(input("salary:"))
msg = '''
------Hi,{0} Welcome to this system ------
Your name is: {0}
Your age is: {1}
Your job is: {2}
Your salary is: {3}
''' .format(Name,Age,Job,Salary)
print(msg)

 

posted on 2017-04-10 14:17  承祥君  阅读(173)  评论(0编辑  收藏  举报

导航