Python First day happy starting!(Day 1)

  • 第一天,我们不玩那么复杂了,先来点能热身的练练手,那就是简单的变量以及逻辑控制。 这些简单的内容一看就会懂,我们不再多说。
  1. For、If...else、while  and break and continue ,use them to start your coding. 
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Yuhao Wang

for i in range(10):
    print(i)

print("=====偶数?步长可以设置为2嘛====")
for j in range(0,10,2):
    print(j)

count = 0
while True:
    user = input("name:")
    if user == "wangyuhao":
        print("you get it")
        break
    else:
        print("oh no!")
        count = count + 1
        if count == 3:
            choice = input("if you want to continue? yes or no")
            if choice == "yes":
                continue
            else:
                break

 

  2.还有一点要说的就是在给print传递参数的几种方法。我们可以看一下

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Yuhao Wang

# (1) print hello world
# print("hello world")
# print("I love you python!")
#
# name = "wangyuhao"
# print("My name is",name)
# name = "zhangsan"
# print("His name is",name)
#

# (2)interaction

username = input("username:")
age = int(input("age:"))
print(type(age))
job = input("job:")
salary = input("salary:")

info = '''
------------ info of %s -----------
Name:%s
Age:%d
Job:%s
Salary:%s
''' % (username,username,age,job,salary)

print(info)
# %s 字符,%d 数字 ,%f 浮点型
# 默认的所有输入都会变成字符串,要做一次强制类型转换 在你定义它的传参为数字的时候

info2 = '''
============ info of {N} ===========
Name:{N}
Age:{A}
Job:{J}
Salary:{S}
'''.format(N=username,A=age,J=job,S=salary)

print(info2)

print("name:" + username + "........")

# 这是第二种传参方式,当然我们不算 字符串拼接 用加号的那种,"Name:" + name 哪种lowb的方式
# 还有其他方式我们不多说了,这两种算是最好用

 

posted @ 2017-03-10 20:34  Gooder丶  阅读(126)  评论(0)    收藏  举报