自学python-3

以下为作业!
#----------------------------20210425------------------------------

#----------------石头剪刀布----------------

import random

num1 = random.randint(1,3)

num2 =int(input('请输入一石头(1),剪刀(2),布(3)'))

print(num1)

if num2 - num1 ==0:

print('平')

elif num2 - num1 == -1:

print('胜')

else:

print('负')

#-------------------算BMI指数-------------------

weight =float(input('请输入你的体重'))

hight =float(input('请输入你的身高'))

BMI = weight / hight **2

if BMI <18.5:

print('你的BMI指数为{:.2f},你的BMI指数过轻'.format(BMI))

elif BMI >18.5 and BMI <=25:

print('你的BMI指数为{:.2f},你的BMI指数正常'.format(BMI))

elif BMI >25 and BMI <=28:

print('你的BMI指数为{:.2f},你的BMI指数过重'.format(BMI))

elif BMI >28 and BMI <=32:

print('你的BMI指数为{:.2f},你的BMI指数肥胖'.format(BMI))

else:

print('你的BMI指数为{:.2f},你的BMI指数严重肥胖'.format(BMI))

#------------模拟取钱----------------

print('还有来到xx银行')

ID =123456

password =654321

money =1232.21

int(ID)

int(password)

float(money)

userID =int(input('请输入账号'))

if userID == ID:

password1 =int(input('请输入密码'))

if password1 == password:

money1 =float(input('请输入取款金额'))

if money - money1 >=0:

print('已成功取款{:.2f}元,余额{:.2f}元'.format(money1, money - money1))

else:

print('余额不足')

else:

print('密码输入有误,请稍后重试')

else:

print('非法账户,请重新输入')

---------------------------------20210425--------------------------

#----------- 打印1-100之间的数字-------------

i=1

while i<=100:

print(i)

i+=1

#------------打印1-100之间的奇数-------------

i=1

while i<=100:

print(i)

i+=2

#------------打印1-100之间的偶数-1--------------------

i=0

while i<=98:

print(i+2)

i+=2

# 打印1-100之间的偶数-2

i =1

while i <=100:

if i %2==0:

print(i)

i +=1

#--------------石头剪刀布玩3把----------------

import random

i =1

while i <4:

i +=1

    num1 = random.randint(1,3)

num2 =int(input('请输入一石头(1),剪刀(2),布(3)'))

print(num1)

if num2 - num1 ==0:

print('平')

elif (num2 - num1 == -1)or (num2 - num1 ==2):

print('胜')

else:

print('负')

#-------------1-100求和--------------

i=0

n=0

while n<100:

n+=1

    i=i+n

print(i)

#---------------------猜数字-------------------------

import random

count =0

num = random.randint(1,100)

b =True

print('愉快的猜数字游戏开始了,看下你是什么段位吧')

while b:

player =int(input('请输入1-100之间任意一个整数'))

if player - num >0:

print('继续加油!你的数字有点大了哟')

elif player - num <0:

print('继续加油!你的数字有点小了哟')

else:

print('太棒了,你猜对了!')

b =False

    count +=1

if count==1:

print('你一共猜了%d次,段位是:王者'%count)

elif count>1 and count <=5:

print('你一共猜了%d次,段位是:大师'%count)

elif count>5 and count <=10:

print('你一共猜了%d次,段位是:钻石'%count)

else:

print('你一共猜了%d次,段位是:青铜'%count)

#------------------------1-100之间偶数求和------------------------

i=0

count=0

while i<=100:

i+=2

    print(i)

count+=i

print(count)

#---------------计算1-2+3-4+5……+99---------------------------

i=0

j=1

num1=0

num2=0

count=0

while i<=100:

i+=2

#    print(i)

    num1-=i

#    print(num1)

while j<=100:

j+=2

#    print(j)

    num2+=j

#    print(num2)

print(num1+num2)

你可能感兴趣的:(自学python-3)