python入门
第一个入门案例
#!user/bin/env python
# -*- coding:utf-8 -*-
print(“hello,word”)
1. if else 例子
- #!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)

浙公网安备 33010602011771号