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)
|