各位朋友们,小编在这里要分享,python简单易懂的小程序 python简单小程序代码,让我们开始吧!
简单Python入门小程序
简单Python入门小程序
1、猜拳击小游戏,三次后结束派森编程软件python好学吗,派森编程软件python下载。石头—0,剪刀-1,布-2,如果输入错误则提示错误输入。
import random
i=0
while 1:
people = int(input('请出拳(石头—0,剪刀-1,布-2):'))
computer = random.randint(0,2)
print(computer)
if people == 0 or people == 1 or people ==2:
if people == computer:
print("平局")
elif people > computer:
print("你赢了!")
print('开心吗?')
else:
print("你输了。")
print('不要难过,下次再来!')
else:
print('输入错误,请输入正确的数字')
i+=1
if i == 3:break
2、九九乘法表
row = 1
while row <=9:
col = 1
while col<=row:
print('%d*%d=%d'%(row,col,row*col),end =" ")
col+=1
pass
print( )
row+=1
pass
3、打印直角三角形
row = 1
while row <= 5:
j = 1
while j <= row:
print('*',end=' ')
j+=1
pass
print()
row += 1
pass
4、打印等腰三角形
row = 1
while row <= 5:
j = 1
while j <= 5-row:
print('#',end='')
j=j+1
k = 1
while k <= 2*row-1:
print('*', end='')
k += 1
print()
row += 1
5、猜年龄小游戏1-100岁,猜对年龄后退出游戏。如果连续三次未猜对,询问用户是否还想继续玩。
import random
Q=1
while Q==1:
for i in range(3):
ag=int(input('请输入年龄:'))
age = random.randint(1, 100)
if ag == age:
print('猜对了!')
print("age={}".format(age))
Q = 0
break
else:
print('猜错了!')
print("age={}".format(age))
if Q==1:
q=input('是否继续玩?(y or n)')
if q=='y':Q=1
if q=='n':Q=0
6、计算BMI---------BMI=体重/身高/身高
sg = float(input('请输入你的身高(m):'))
tz = float(input('请输入你的(kg体重):'))
BMI= tz/sg/sg
if BMI<18.5:print('过轻')
elif BMI>=18.5 and BMI <25:print('正常')
elif BMI>=25 and BMI <28:print('过重')
elif BMI>=28 and BMI <32:print('肥胖')
else:print('严重肥胖')
原文地址1:https://blog.csdn.net/qq_41575002/article/details/125783658
python手册 http://www.78tp.com/python/