码迷,mamicode.com
首页 > 编程语言 > 详细

第一天Python

时间:2018-05-09 22:45:38      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:confirm   linu   conf   NPU   ase   bin   password   乘法   you   

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

一、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循环语句

 

第一天Python

标签:confirm   linu   conf   NPU   ase   bin   password   乘法   you   

原文地址:https://www.cnblogs.com/zheng-weimin/p/9016772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!