继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

python基础

萌萌小温柔
关注TA
已关注
手记 306
粉丝 56
获赞 401

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


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP