python学习第一天

python学习第一天

1、小游戏

import random

while True:
    user = int(input("用户请出拳(0:退出游戏,1:石头,2:剪刀,3:布)"))
    if user == 1 or user == 2 or user == 3:
        pass

    elif user == 0:
        print("game over")
        break
    else:
        print("请从新出拳必须是1,2或者3")
        continue

    computer = random.randint(1, 3)
    print("user:", user, "computer:", computer)

    if user == computer:
        print("平局")
    elif (user == 3 and computer == 1) or (user == 2 and computer == 3) or (user == 1 and computer == 2):
        print("用户赢")
    else:
        print("电脑赢")

2、for循环

big="adasdad1"
for i in big:
    print(i)
for index,i in enumerate(big):
    if i=="a":
        continue
        print(index,1)
    print(i,end=",")

3、while循环

#
# i = 0
# while i < 4:
#    print(i + 1, "吃苹果")
#    j = 1
#    while j <= 4:
#          print(j, "吃橘子")
#          if j == 2:
#              print("我吃饱了")
#              break
#          j += 1
#    i += 1
#
#
# i = 1
# while i <= 4:
#     if i == 3:
#         i += 1
#         continue
#     print(f"吃{i}个苹果")
#     i += 1
#
# print("===========")
# str="python"
# j = 0
# while j <6:
#     if j == 1 or j ==4:
#         print(str[j])
#     j += 1
#
#
# for i in  "aaaa":
#     if i =="m":
#         continue
#     print(i,end=' ')



for i in range(1,6):
    print("*" * i)

for i in range(1,6):
    if i % 2 == 1:
        print("*" * i)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值