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

python入门

时间:2017-08-27 12:46:47      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:use   count   big   一个   str   --   for循环   案例   while循环   

第一个入门案例

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

    print(“hello,word”)

1. if  else 例子

  1. #!user/bin/env python
    # -*- coding:utf-8 -*-
    age=58
    thinkAge=input("age:")
    thinkAge=int(thinkAge)
    if age==thinkAge:
        print("you think is right")
    elif age>thinkAge:
        print("please think bigger")
    else:
        print("please thinking smaller")

2.While循环

count=0
age=54
while count<3:
    inputage = int(input("age:"))
    count += 1
    if age==inputage:
        print("you are right",age)
        break
    elif
age>inputage:
        print("you think small")

    else:
        print("you think big")

3.while循环也有else

age=58
count=0
while count<3:
    count+=1
    thinkAge=int(input("age:"))
    if age==thinkAge:
        print("you are right")
        break
    elif
age>thinkAge:
        print("small")
    else:
        print("bigger")
else:
    print("you can try three times,you can input!")

4.for循环入门打印0--9

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

 

5.for循环+if  elif

for i in range(3):
    age=int(input("age:"))
    if age==4:
        print("right")
        break
    elif
age<4:
        print("you are small")
    else:
        print("big")
else:
    print("you childen is‘t to learn in 小学")

6.for隔行打印0开始的10个数,打印0,2,4,6,8

for a in range(0,10,2):
    print(a)

7.打1开始的10个数,打印1,3,5,7,9

for a in range(1,10,2):
    print(a)

 

python入门

标签:use   count   big   一个   str   --   for循环   案例   while循环   

原文地址:http://www.cnblogs.com/tajinshi/p/7440010.html

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