python小练习:质数之和;求100以内所有7的倍数之和,以及个数;水仙花数;打印5*5星号图;打印9*9乘法表;100以内所有质数;唐僧大战白骨精

2020-5-8 Python基础第一模块练习

from time import *



#------------------------求质数之和-------------------
x=1
sum=0
while x<100 and x%2 !=0 :
    x+=2
    sum +=x

else :
    print('finished')
print(sum)

#-------------求100以内所有7的倍数之和,以及个数---------------------

a=7
sum=7
count=0
while a<100 and a%7 ==0:
    sum+=a
    count+=1
    print(a)
    a += 7
else:
    print('finised')
print('和为:',sum)
print('个数为:',count)

#--------------------水仙花数-------------------------

x=100
while x<1000:
    a=x//100
    b=x//10%10
    #b=(x-a*100)//10
    c=x%10
    if a**3+b**3+c**3 ==x :
        print(x)
    x+=1

#--------------------------判断是否为质数----------------------------
num=int(input('输入一个任意大于1的数:'))
a=2
flag=True
while a<num:
    if num%a==0:
         flag=False
    a+=1

if flag:
    print(num,"是质数")
else:
    print('不是质数')


#-------打印5*5星号图形----------------------------------
i=0
while i<5:
    j=5
    while i<j:
        print('*',end='')
        j-=1
    print()
    i+=1
#----------打印9*9乘法表-----------------------------------
i=0
while i<9:
    i+=1
    j=0
    while j<i:
        j+=1
        print(f'{j}*{i} ',end='')
    print()
#--------100以内所有质数--------------------------------------


begin = time()
x=2
while x<=100:
    flag=True
    i=2
    while x>i:
        if x%i==0 :
           flag=False
           break
        i+=1
    if flag:
        print(x)
    x+=1
end= time()
print('time=',end-begin,'s')
#-------------------小游戏开发------------------------------------


#----游戏欢迎信息--------
print('-'*20,'welcome to this little game','-'*20)
print('please choose your indentity:')
print('\t1.monk')
print('\t2.white bone demon')

player_choose=input('请选择[1-2]:')
print('-'*100)
if player_choose=='1':
    print('you have chosen monk, which is your identity to play game')
elif player_choose=='2':
    print('you have chosen demon, which is too impractical. So you will be automatically designed to monk')
else:
    print('your choose is wrong, and your will be assigned to monk to play the game ')
#------进入游戏----------
player_life=2
player_attack=2
boss_life=10
boss_attack=10

print(f'monk,your life value is {player_life}, and your attach value is {player_attack}')

while True:
    print('-' * 100)
    print('please choose your upcoming operation:')
    print('\t1. leveling')
    print('\t2. fight boss')
    print('\t3. run away')
    game_choose=input('please chose your operation[1-3]:')
    if game_choose=='1':
        player_life+=2
        player_attack+=2
        print('-' * 100)
        print(f'woo, congratulations! Monk,your life value is {player_life}, and your attach value is {player_attack}')
    elif game_choose =='2':
        boss_life-=player_attack

        if boss_life<=0:
            print('you win!!!')
            break

        player_life-=boss_attack
        print('-' * 100)
        print('you are hurt')
        if player_life<=0:
            print('game over')
            print('-' * 100)
            break
    elif game_choose=='3':
        print('-' * 100)
        print('monk is so scared, game over....')
        print('-' * 100)
        break
    else:
        print('-' * 100)
        print('your input is wrong, please retype your choose.')
        print('-' * 100)











 





  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值