第一天Python

断断续续和反复了几次,今天开始老实的写笔记和画流程图:

一、python格式:

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

二、基本的输入框和打印:

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

print("Hello world!")

name = input("Name:")
age = input("Age:")
job = input("Job")

info1 = """
==================== info1 of %s ==================
name:%s
age:%s
job:%s
""" % (name,name,age,job)

info2 = """
==================== info2 of {Name} ==================
name:{Name}
age:{Age}
job:{Job}
""".format(Name=name,Age=age,Job=job)

info3 = """
==================== info3 of {0} ==================
name:{0}
age:{1}
job:{2}
""".format(name,age,job)

print(info1,info2,info3)
基本的输入框和打印

三、if判断语句:

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

import getpass  #只能在Linux下使用

name = "jack"
passwd = "jack123"

user = input("Please input your name:")
#password = input("Please input your passwd:")
password = getpass.getpass("Please input your passwd:")

if user == name and passwd == password:
    print("Welcome %s" % user)
else:
    print("get out")
if判断语句

四、while循环:

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

# count = 0
#
# while count <3:
#     num = int(input("Please input num:"))
#     if num == 22:
#         print("your are rigth")
#         break
#     elif num > 22:
#         print("bigger")
#     else:
#         print("smaller")
#     count = count + 1
# else:
#     print("You have tried too many times..")


count = 0
while count <3 :
    num = int(input("Please input num:"))
    if num == 22:
        print("your are rigth")
        break1
    elif num > 22:
        print("bigger")
    else:
        print("smaller")
    count = count + 1

    if count ==3:
        confirm = input("Do you want to continue...")
        if confirm != "n":
            count = 0
While循环使用

五、for循环

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

#for循环
for i in range(10):
    print(i)

#for循环,打印奇数
for i in range(1,10,2):  #三个参数:[开始、结束)步长
    print(i)

#for循环,打印偶数
for i in range(0,10,2):
    print(i)

#九九乘法表
for i in range(1,10):
    for j in range(1,10):
        if j <= i:
            print(j,"*",i,"=",i*j)
for循环语句

 

posted @ 2018-05-09 21:27  zheng-weimin  阅读(146)  评论(0编辑  收藏  举报