练习题:
1.已知有如下字符串
第一问:将所有空格去掉并保存在一个另外一个新的字符串里并打印新字符串。
第二问:求上述单词个数(要求用到字符串分割转成数组,数字算单词的情况下)并打印。
第三问:把以上所有以t(不区分大小写)开头的单词都找出来并打印。
content_text = 'I am Guido van Rossum I have over the 8 years of experience in marketing I am the team manager of marketing for trip HP since 2013 Thanks
2.ATM机输密码,账户余额为:700元,正确密码为:123456,要求密码错误三次后提示卡已被锁请联系银行工作人员,如果密码正确则进入系统,然后提示用户输入取多少钱,如果账户余额大于用户输入余额则打印您本次取现xxx元成功,余额为xxx元,如果账户余额小于用户输入的金额则打印您的账户余额不足。
3.打印1-100之间所有的偶数。(能被2整除的数即为偶数)
4.创建一个数组,包含0-100并输出数组
5.求1-100相加的和
附加题:
玩家Player拥有俩个技能,乾坤一掷(伤害225),戒骄戒躁(伤害360)伤害类型为物理非纯粹伤害,BOSS初始护甲为8点(每有一点护甲可抵挡4点物理伤害),BOSS血量为800PH,当BOSS被攻击时,每失去10点血,则增加一点护甲值(护甲值可累计,护甲值上限为50),当BOSS血量低于300则触发被动,为BOSS回复300生命值(此被动只会被触发一次)
player_hero_name = 'Player' mt_hero_name = 'BOSS' mt_hero_ph = 800 player_hero_skill1 = '乾坤一掷' player_hero_skill2 = '戒骄戒躁' player_hero_skill1_damage = '225' player_hero_skill2_damage = '360' mt_hero_armor = 8 # boos 被动 is_boss_buff_can_be_used = True while True: user_skill_input = input("请输入你要使用的技能 ->1.乾坤一掷 2.戒骄戒躁") if user_skill_input == "1": # 乾坤一掷 total_damage = int(player_hero_skill1_damage) - 4 * mt_hero_armor mt_hero_ph = mt_hero_ph - total_damage print("{}使用了{}技能,击打了{},造成{}伤害,{}的剩余血量为{}".format(player_hero_name, player_hero_skill1, mt_hero_name, total_damage, mt_hero_name, mt_hero_ph)) else: # 戒骄戒躁 total_damage = int(player_hero_skill2_damage) - 4 * mt_hero_armor mt_hero_ph = mt_hero_ph - total_damage print("{}使用了{}技能,击打了{},造成{}伤害,{}的剩余血量为{}".format(player_hero_name, player_hero_skill2, mt_hero_name, total_damage, mt_hero_name, mt_hero_ph)) # 护甲 if mt_hero_armor + int(total_damage / 10) > 50: mt_hero_armor = 50 print("护甲为{}点".format(mt_hero_armor)) else: mt_hero_armor = mt_hero_armor + int(total_damage / 10) print("护甲为{}点".format(mt_hero_armor)) # 被动 if mt_hero_ph <= 300 and is_boss_buff_can_be_used: mt_hero_ph += 300 is_boss_buff_can_be_used = False print("boss生命值低于300,触发了被动,现在生命值为:{}".format(mt_hero_ph)) # 终止条件 if mt_hero_ph <=0: print("恭喜您,成功的击败了BOSS!获得奖励~~~!!!") break