栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python基础

1.输入输出。

用户输入:


name = input("username:")        #在py2里用raw_input输入,同input

passwd = input("password:")

age = int(input ("age:"))

输出1


print(type(age))    #输出变量类型,默认是str

print(name,passwd)


输出2


info1 = '''

------------info of  ---------------

username:%s

password:%s

age:%d

'''%(name,passwd,age)

print(info1)


输出2


info2 = '''

-----------info of {_name}-----------------

username:{_name}

password:{_password}

age:{_age}

'''.format(_name=name,

            _password=passwd,

            _age=age,

             )

print(info2)

2.getpass加密


import getpass

username = "fengxiaoli"

password = "123456"

name = input("username:")

passwd = getpass.getpass("password:")   #注getpass模块在pycharm执行不成功,可以在命令行执行测试

if name == username and passwd == password:

    print("welcome {_username} login".format(_username=name))

else:

    print("invalid login")

3.while,for循环


#猜数字1

age = 50

count=0

while count < 3:

    _age = int(input("age:"))

    if _age == age :

        print("you guessed right")

        break

    elif _age > age:

         print("The number is too big")

    else:

         print ("The number is too small")

    count +=1

else :

    print("You tried too many times")


猜数字2

age = 50

for i in range(3):

    _age = int(input("age:"))

    if _age == age :

        print("you guessed right")

        break

    elif _age > age:

         print("The number is too big")

    else:

         print ("The number is too small")

else :

    print("You tried too many times")


猜数字3

age = 50

count=0

while count < 3:

    _age = int(input("age:"))

    if _age == age :

        print("you guessed right")

        break

    elif _age > age:

         print("The number is too big")

    else:

         print ("The number is too small")

    count +=1

    if count == 3:

        continue_confirm=input("do you want continue.....?")

        if continue_confirm != "n":

            count = 0


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/225163.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号