python简单练习
2017-07-18 19:27
225 查看
1.py hello python
print("Hello python")
print("hello world")
2.py 变量计算
num1=100
num2=200
result=num1+num2
print(result)
3.py 名片制作
#输入名字
name = "fanfen"
#输入年龄
age = 28
#输入电话号码
mobile_num = 18875992320
#输入公司地址
add = "北京昌平"
#输出名片
print("==================\n姓名:%s\n年龄:%d\n手机号码:%d\n公司地址:%s\n=================="%(name,age,mobile_num,add))
4.py if 语句判断是否成年
ge = int(input("请输入年龄:"))
if age>=18:
print("已成年")
else:
print("未成年")
print("程序结束")
5.py if 嵌套上公交
#coding = utf-8
balance = int(input("Please input the Bus card balance:"))
emptySeat = int(input("Please input the empty seat number:"))
if balance>=2:
print("You can get on the bus.")
if emptySeat!=0:
print("You can have a seat.")
else: print("You can't have a seat.")
else:
print("You can't get on the bus.")
6.py elif语句猜拳游戏
import random
player = int(input('请输入:石头(0),剪刀(1),布(2):'))
computer = random.randint(0,2)
if (player == 0 and computer ==1)or(player == 1 and computer == 2) or (player == 2 and computer == 0):
print("You win!")
elif (player == computer):
print("呵呵,暂时平局")
else:
print("You lose!")
7.py while累加1-100
#/usr/bin/python3
#coding=utf-8
i=0
sum = 0
while i<=100:
if i%2 == 0:
sum+=i
print("i=%d sum=%d"%(i,sum))
i+=1
print("程序结束")
8.py while 打印*号
#coding = utf-8
n=1
while n<=5:
i=1
while i<=n:
print("*",end="")
i+=1
print()
n+=1
9.py while嵌套九九乘法表
#coding=utf-8
j=1
while j<=9:
i=1
while i<=j:
print("%d*%d=%d "%(j,i,i*j),end="")
i+=1
print()
j+=1
for i in range(1, 10):
for j in range(1, i+1):
print("%d * %d = %d " % (j, i, i*j), end="\t")
print()
10.py while 倒三角形
#coding=utf-8
j=5
while j>=1:
i=1
while i<=j:
print("*",end="")
i+=1
print()
j-=1
11.py while 两三角形对接
#coding = utf-8
#N=int(input("Please input a number that above 7:"))
N=9
j=1
while abs(N-j)/2<=(N-1)/2:
i=1
while i<=abs(N-j)/2:
print(" ",end="")
i+=1
i=1
while i<=(N-abs(N-j)):
print("*",end="")
i+=1
j+=2
print()
print("Hello python")
print("hello world")
2.py 变量计算
num1=100
num2=200
result=num1+num2
print(result)
3.py 名片制作
#输入名字
name = "fanfen"
#输入年龄
age = 28
#输入电话号码
mobile_num = 18875992320
#输入公司地址
add = "北京昌平"
#输出名片
print("==================\n姓名:%s\n年龄:%d\n手机号码:%d\n公司地址:%s\n=================="%(name,age,mobile_num,add))
4.py if 语句判断是否成年
ge = int(input("请输入年龄:"))
if age>=18:
print("已成年")
else:
print("未成年")
print("程序结束")
5.py if 嵌套上公交
#coding = utf-8
balance = int(input("Please input the Bus card balance:"))
emptySeat = int(input("Please input the empty seat number:"))
if balance>=2:
print("You can get on the bus.")
if emptySeat!=0:
print("You can have a seat.")
else: print("You can't have a seat.")
else:
print("You can't get on the bus.")
6.py elif语句猜拳游戏
import random
player = int(input('请输入:石头(0),剪刀(1),布(2):'))
computer = random.randint(0,2)
if (player == 0 and computer ==1)or(player == 1 and computer == 2) or (player == 2 and computer == 0):
print("You win!")
elif (player == computer):
print("呵呵,暂时平局")
else:
print("You lose!")
7.py while累加1-100
#/usr/bin/python3
#coding=utf-8
i=0
sum = 0
while i<=100:
if i%2 == 0:
sum+=i
print("i=%d sum=%d"%(i,sum))
i+=1
print("程序结束")
8.py while 打印*号
#coding = utf-8
n=1
while n<=5:
i=1
while i<=n:
print("*",end="")
i+=1
print()
n+=1
9.py while嵌套九九乘法表
#coding=utf-8
j=1
while j<=9:
i=1
while i<=j:
print("%d*%d=%d "%(j,i,i*j),end="")
i+=1
print()
j+=1
for i in range(1, 10):
for j in range(1, i+1):
print("%d * %d = %d " % (j, i, i*j), end="\t")
print()
10.py while 倒三角形
#coding=utf-8
j=5
while j>=1:
i=1
while i<=j:
print("*",end="")
i+=1
print()
j-=1
11.py while 两三角形对接
#coding = utf-8
#N=int(input("Please input a number that above 7:"))
N=9
j=1
while abs(N-j)/2<=(N-1)/2:
i=1
while i<=abs(N-j)/2:
print(" ",end="")
i+=1
i=1
while i<=(N-abs(N-j)):
print("*",end="")
i+=1
j+=2
print()
相关文章推荐
- [python]一个简单的听写练习工具
- 【Python】Learn Python the hard way, ex35 通过一个简单游戏,练习循环和分支语句
- 机器学习算法练习之(二):Python和Tensorflow分别实现简单的神经网络
- python简单练习2
- Python小练习 - python编写巨简单的闹钟功能
- Python小练习 - 用字典编写简单的注册、登录程序
- python学习第二章变量和简单数据类型的部分课后练习自己尝试的代码
- 【python小练习】简单的猜数字游戏
- python3 的简单练习
- Python小练习——创建简单地址簿
- Python简单实现KNN算法及绘图练习
- python爬虫小练习之五:requests库小练习(58同城2手手机简单)
- python练习五—简单web应用
- python练习1(简单爬虫)
- Python基于Kmeans算法实现文本聚类的简单练习
- python练习六—简单的论坛
- Python小练习-实现简单端口扫描~
- 一个简单的python练习
- 笨办法学 Python · 续 练习 36:简单的计算器
- 《Python-yield的简单练习》---yield实现单线程下的并行