当前位置:   article > 正文

2021-04-21_matlab邮件地址切片器

matlab邮件地址切片器

python 迷你程序 (1)

1、骰子模拟器

  1. import random
  2. while int(input('Press 1 to roll the dice or 0 to exit:\n')):
  3. print(random.randint(1, 6))
  4. # Press 1 to roll the dice or 0 to exit:
  5. # 5
  6. # 4

2、石头剪刀布

  1. import random
  2. choices = ["石头", "布", "剪刀"]
  3. computer = random.choice(choices)
  4. player = False
  5. cpu_score = 0
  6. player_score = 0
  7. while True:
  8. player = input("石头,布 or 剪刀?:").capitalize()
  9. # 判断游戏者和电脑的选择
  10. if player == computer:
  11. print('平局!')
  12. elif player == "石头":
  13. if computer == "布":
  14. print("player输了")
  15. cpu_score += 1
  16. else:
  17. print("player赢了")
  18. player_score += 1
  19. elif player == "剪刀":
  20. if computer == "石头":
  21. print("player输了")
  22. cpu_score += 1
  23. else:
  24. print("player赢了")
  25. player_score += 1
  26. elif player == "布":
  27. if computer == "剪刀":
  28. print("player输了")
  29. cpu_score += 1
  30. else:
  31. print("player赢了")
  32. player_score += 1
  33. elif player == 'E':
  34. print('Final Scores:')
  35. print(f"CPU:{cpu_score}")
  36. print(f"Player:{player_score}")
  37. break
  38. else:
  39. print("This is not a valid word.Check your spelling")
  40. computer = random.choice(choices)
  41. # 石头,布 or 剪刀?:石头
  42. # player赢了
  43. # 石头,布 or 剪刀?:E
  44. # Final Scores:
  45. # CPU:0
  46. # Player:1

3、邮件地址切片器

  1. email = input("请输入你的邮箱:").strip()
  2. user_name = email[:email.index("@")]
  3. domain_name = email[email.index("@")+1:]
  4. result = f"你的用户名是{user_name},你的域名是{domain_name}"
  5. print(result)
  6. # 请输入你的邮箱:1147567638@qq.com
  7. # 你的用户名是1147567638,你的域名是qq.com

4、自动发送邮件

  1. import smtplib
  2. from email.message import EmailMessage
  3. email = EmailMessage()
  4. email['from'] = 'rose'
  5. email['to'] = '123456'
  6. email['subject'] = 'welcome'
  7. email.set_content('Welcome to China!!!')
  8. with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
  9. smtp.ehlo()
  10. smtp.starttls()
  11. smtp.login("email_id", "Password")
  12. smtp.sendmail(email)
  13. print("The mail has been sent")

5、读女友来信 —— 冒险游戏

  1. name = str(input("输入你的名字:"))
  2. print(f'{name} 你的女友给你发了一条短信,询问你是否下课后和她一起吃饭。你的任务是回答让你的女友开心')
  3. print("现在回答开始")
  4. print("1.当然去了 2.当然去了,honey!")
  5. response = int(input("选择一个数字 1 or 2:"))
  6. if response == 1:
  7. print("女友现在很生气")
  8. elif response == 2:
  9. print("女友开心了")
  10. else:
  11. print("你死定了!")
  12. # 输入你的名字:ll
  13. # ll 你的女友给你发了一条短信,询问你是否下课后和她一起吃饭。你的任务是回答让你的女友开心
  14. # 现在回答开始
  15. # 1.当然去了 2.当然去了,honey!
  16. # 选择一个数字 1 or 2:4
  17. # 你死定了!

6、Hangman游戏 —— 一个猜单词的双人游戏

  1. import time
  2. import random
  3. name = input("输入你的名字:")
  4. print("你好" + name, "欢迎来到Hangman游戏!!")
  5. time.sleep(1)
  6. print("开始游戏!\n")
  7. time.sleep(0.5)
  8. words = ['Python', "Programming", "treasure", "creative", "medium", "horror"]
  9. word = random.choice(words)
  10. guesses = ''
  11. turns = 5
  12. while turns > 0:
  13. failed = 0
  14. for char in word:
  15. if char in guesses:
  16. print(char, end="")
  17. else:
  18. print("_", end="")
  19. failed += 1
  20. if failed == 0:
  21. print("\n你赢了!!")
  22. break
  23. guess = input("\n guess a character:")
  24. guess += guess
  25. if guess not in word:
  26. turns -= 1
  27. print("\n错误")
  28. print("\n你还有", + turns, "次机会")
  29. if turns == 0:
  30. print("\n你输了...")
  31. # 输入你的名字:l
  32. # 你好l 欢迎来到Hangman游戏!!
  33. # 开始游戏!
  34. # ________
  35. # guess a character:pp
  36. # 错误
  37. # 你还有 4 次机会

本文内容大多来自于 公众号 —— python数据之道

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/92157
推荐阅读
相关标签
  

闽ICP备14008679号