Python 官方文档:入门教程 => 点击学习
一:python的用户输入: 1.1 Python的输入 #!/usr/bin/env python # -*- coding: utf-8 -*- # Author:FlyFish #import getpass _username
一:python的用户输入:
1.1 Python的输入
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:FlyFish
#import getpass
_username = "zhangyy"
_passWord = "abc123"
username = input("username:")
password = input("password:") ### password = getpass.getpass("password:")
if _username == username and _password == password:
print("Welcom user {name} login".fORMat(name=username))
else:
print("Invalid username or password ")
二:if....else 循环:
在程序里设定好你的年龄,然后启动程序让用户猜测,用户输入后,根据他的输入提示用户输入的是否正确,如果错误,提示是猜大了还是小了
注释:
外层变量,可以被内层代码使用
内层变量,不应被外层代码使用
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:FlyFish
age_of_zhangyy = 26
guess_age = int(input("guess zhangyyy age:"))
if guess_age == age_of_zhangyy:
print("yes,yo Go it")
elif guess_age > age_of_zhangyy:
print("think smaller...")
else:
print("think bigger")
三:while的循环
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:FlyFish
count = 0
while True:
print("count",count)
count = count + 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:FlyFish
age_of_zhangyy = 26
count = 0
while True:
if count == 3:
break
guess_age = int(input("guess zhangyyy age:"))
if guess_age == age_of_zhangyy:
print("yes,yo go it")
break
elif guess_age > age_of_zhangyy:
print("think smaller...")
else:
print("think bigger")
count+=1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:FlyFish
age_of_zhangyy = 26
count = 0
while count<3:
guess_age = int(input("guess zhangyyy age:"))
if guess_age == age_of_zhangyy:
print("yes,yo go it")
break
elif guess_age > age_of_zhangyy:
print("think smaller...")
else:
print("think bigger")
count+=1
if count ==3:
countine_confirm = input("do you want to guessing....")
if countine_confirm !='n':
count ==0
else:
print("you have tried too many times..fuck off")
三:Python的模块知识:
Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持,以后的课程中会深入讲解常用到的各种库,现在,我们先来象征性的学2个简单的。
--结束END--
本文标题: Python学习系列 ( 第二章):Py
本文链接: https://lsjlt.com/news/183146.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0