赞
踩
import random
rand_x = random.randint(0,99)# 生成 0-99范围的随机数
rand_y = random.randint(0,199)# 生成 0-199范围的随机数
print(rand_x,rand_y)
if rand_x > rand_y:
print(rand_x)
elif rand_x < rand_y:
print(rand_y)
elif rand_x == rand_y:
rand_z = rand_x + rand_y
print(rand_z)
i=0
while i<9:#控制列
i=i+1
j = 0
while j<9:#控制行
if j<i:
j = j + 1
print(j,end="")
elif j==i:
print("")
break
sum1 = 0
num1 = 1
while( num1 < 1000):
if( num1 % 2 !=0 ):
sum1 += num1
num1 +=1
print(sum1)
sum = 0
num1 = 0
while num1 < 100:
num1 += 1
if num1 % 7 ==0:
sum += 1
print(sum)
sum = 0
num1 = 0
while num1 < 100:
num1 += 1
if num1 % 3 ==0 :
sum += 1
elif num1 %7 == 0:
sum += 1
elif num1 %(3*7) ==0:
sum -= 1
print(sum)
sum = 0
num = 3000
while num >=5:
num -= num/2
sum += 1
print(sum)
num = int(input("请输入一个整数:"))
num1 = str(num)
print(len(num1))
for num1 in range(100,1000): #循环遍历生成三位数的num1
num1 = str(num1) #将num1转为字符串
num2 = int(num1[0]) #获取num1的百位数字
num3 = int(num1[1]) #获取num1的十位数字
num4 = int(num1[2]) #获取num1的个位数字
if int(num1) == num2 ** 3 + num3 ** 3 + num4 ** 3: #判断num1是否是水仙花数,如果是,就输出
print(num1)
import random import sys flag_int =1 while flag_int: rand_int = random.randint(1, 3) # 生成 1-3范围的随机数 系统后台出拳 your_int = int(input("请输入你要出的拳:石头(1)/剪刀(2)/布(3)/我不玩了(4):")) #玩家出拳 if rand_int == 1: if your_int == 1: print("电脑:石头(%d),你:石头(%d);平局" % (rand_int,your_int)) elif your_int == 2: print("电脑:石头(%d),你:剪刀(%d);你输了" % (rand_int, your_int)) elif your_int == 4: print("好吧,拜拜") sys.exit(1) else: print("电脑:石头(%d),你:布(%d);你赢了" % (rand_int, your_int)) # 胜利后询问并判断用户输入 pd = int(input("您是否要继续玩?(yes[1]/no[0])")) if pd == 1: flag_int = 1 elif pd == 0: print("好吧,拜拜") sys.exit(1) elif rand_int == 2: if your_int == 1: print("电脑:剪刀(%d),你:石头(%d);你赢了" % (rand_int, your_int)) # 胜利后询问并判断用户输入 pd = int(input("您是否要继续玩?(yes[1]/no[0])")) if pd == 1: flag_int = 1 elif pd == 0: print("好吧,拜拜") sys.exit(1) elif your_int == 2: print("电脑:剪刀(%d),你:剪刀(%d);平局" % (rand_int, your_int)) elif your_int == 4: print("好吧,拜拜") sys.exit(1) else: print("电脑:剪刀(%d),你:布(%d);你输了" % (rand_int, your_int)) else: if your_int == 1: print("电脑:布(%d),你:石头(%d);你输了" % (rand_int, your_int)) elif your_int == 2: print("电脑:布(%d),你:剪刀(%d);你赢了" % (rand_int, your_int)) # 胜利后询问并判断用户输入 pd = int(input("您是否要继续玩?(yes[1]/no[0])")) if pd == 1: flag_int = 1 elif pd == 0: print("好吧,拜拜") sys.exit(1) elif your_int == 4: print("好吧,拜拜") sys.exit(1) else: print("电脑:布(%d),你:布(%d);平局" % (rand_int, your_int))
&
import random flag_int = 1 while flag_int: # 1.让用户输入 player = int(input("请出拳 石头(0)剪刀(1)布(2):")) if len(str(player)) != 1: print("请正确输入!") flag_int = 1 elif len(str(player)) == 1: # 2.计算机产生随机数 computer = random.randint(0, 2) # 3.比较胜负 if ((player == 0) and (computer == 1)) or ((player == 1) and (computer == 2)) or ((player == 2) and (computer == 0)): print("玩家胜利") pd = int(input("您是否要继续玩?(yes[1]/no[0])")) if pd == 1: flag_int = 1 elif pd == 0: print("好吧,拜拜") break elif player == computer: print("平局") else: print("电脑胜利")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。