成都趣题 第500001期 十点半
本帖最后由 hveagle 于 2023-1-11 17:17 编辑成都趣题 第500001期 十点半
游戏玩法:
十点半
参考答案:
**** Hidden Message *****
奖励区:
名次第1名第2名第3名第4名第5名
谁等待着变成王者登上宝座~
语言
几楼
奖励展示+8荣誉7鱼币2贡献1技术值最佳答案展示+4荣誉4鱼币展示+3荣誉3鱼币展示+2荣誉展示
下一期
评分: 本帖最后由 sfqxx 于 2023-1-8 16:14 编辑
@hveagle 在哪玩?怎么玩才能获得奖励? sfqxx 发表于 2023-1-8 16:10
@hveagle 在哪玩?怎么玩才能获得奖励?
发趣题 哦{:10_277:} 那我要完了
我不会 sfqxx 发表于 2023-1-8 16:17
那我要完了
我不会
你发Scratch 代码怎么发(除图片) 它是一块一块的 然后我要做什么? zhangjinxuan 发表于 2023-1-8 18:40
然后我要做什么?
你报名了吗? 没看懂{:10_269:} 本帖最后由 AhrimanSefid 于 2023-1-8 21:12 编辑
import random
cards = {"A":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"J":0.5,"Q":0.5,"K":0.5,"Little Joker":0.5,"Big Joker":0.5}
player = True
player_card = []
player_card_number = []
computer = True
computer_card = []
computer_card_number = []
print("目前有这些卡牌:")
for item in cards.keys():
print(item)
for i in range(5):
player_card.append(random.sample(cards.keys,1))
player_card_number.append(player_card)
computer_card.append(random.sample(cards.keys,1))
computer_card_number.append(computer_card)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
print("玩家的牌是:",player_card)
print("玩家总共有",str(player_number_total),"点")
print("电脑的牌是:",computer_card)
print("电脑总共有",str(computer_number_total),"点")
if player_number_total > 10.5:
print("你被淘汰了哟")
player = False
else:
pass
if computer_number_total > 10.5:
print("电脑被淘汰了")
computer = False
else:
pass
if player == True and computer == True:
print("你们还可以继续游戏")
if player_number_total != 10.5 and computer_number_total != 10.5:
player_ask_number = int(input("你想要再抽几张牌?(1~4)"))
computer_ask_number = random.randint(1,4)
for i in range(player_ask_number):
player_card.append(random.sample(cards.keys,1))
player_card_number.append(player_card)
for i in range(computer_ask_number):
computer_card.append(random.sample(cards.keys,1))
computer_card_number.append(computer_card)
player_number_len = len(player_card_number)
computer_number_len = len(computer_card_number)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
if player_number_total > 10.5 and computer_number_total > 10.5:
print("都没有赢哟,再来一局吧")
elif player_number_total <= 10.5 and computer_number_total > 10.5:
print("哈,你赢了,祝贺")
elif player_number_total > 10.5 and computer_number_total <= 10.5:
print("电脑赢了,继续加油")
else:
if player_number_total > computer_number_total:
print("哈,你赢了,祝贺")
elif player_number_total < computer_number_total:
print("电脑赢了,继续加油")
else:
print("平局哟,再来一局吧")
elif player_number_total == 10.5 and computer_number_total != 10.5:
print("哈,你赢了,祝贺")
elif player_number_total != 10.5 and computer_number_total == 10.5:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
elif player == True and computer == False:
print("哈,你赢了,祝贺")
elif player == False and computer == True:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
耗时1.5小时,干就完了
PS:由于是直接写,没有调试,可能会报错,后面我会修改的 AhrimanSefid 发表于 2023-1-8 21:05
耗时1.5小时,干就完了
PS:由于是直接写,没有调试,可能会报错,后面我会修改的
修改:TypeError: Population must be a sequence.For dicts or sets, use sorted(d).
import random
cards = {"A":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"J":0.5,"Q":0.5,"K":0.5,"Little Joker":0.5,"Big Joker":0.5}
player = True
player_card = []
player_card_number = []
computer = True
computer_card = []
computer_card_number = []
print("目前有这些卡牌:")
for item in cards.keys():
print(item)
for i in range(5):
player_card.append(random.sample(list(cards.keys),1))
player_card_number.append(player_card)
computer_card.append(random.sample(list(cards.keys),1))
computer_card_number.append(computer_card)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
print("玩家的牌是:",player_card)
print("玩家总共有",str(player_number_total),"点")
print("电脑的牌是:",computer_card)
print("电脑总共有",str(computer_number_total),"点")
if player_number_total > 10.5:
print("你被淘汰了哟")
player = False
else:
pass
if computer_number_total > 10.5:
print("电脑被淘汰了")
computer = False
else:
pass
if player == True and computer == True:
print("你们还可以继续游戏")
if player_number_total != 10.5 and computer_number_total != 10.5:
player_ask_number = int(input("你想要再抽几张牌?(1~4)"))
computer_ask_number = random.randint(1,4)
for i in range(player_ask_number):
player_card.append(random.sample(list(cards.keys),1))
player_card_number.append(player_card)
for i in range(computer_ask_number):
computer_card.append(random.sample(list(cards.keys),1))
computer_card_number.append(computer_card)
player_number_len = len(player_card_number)
computer_number_len = len(computer_card_number)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
if player_number_total > 10.5 and computer_number_total > 10.5:
print("都没有赢哟,再来一局吧")
elif player_number_total <= 10.5 and computer_number_total > 10.5:
print("哈,你赢了,祝贺")
elif player_number_total > 10.5 and computer_number_total <= 10.5:
print("电脑赢了,继续加油")
else:
if player_number_total > computer_number_total:
print("哈,你赢了,祝贺")
elif player_number_total < computer_number_total:
print("电脑赢了,继续加油")
else:
print("平局哟,再来一局吧")
elif player_number_total == 10.5 and computer_number_total != 10.5:
print("哈,你赢了,祝贺")
elif player_number_total != 10.5 and computer_number_total == 10.5:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
elif player == True and computer == False:
print("哈,你赢了,祝贺")
elif player == False and computer == True:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
AhrimanSefid 发表于 2023-1-8 21:13
修改:TypeError: Population must be a sequence.For dicts or sets, use sorted(d).
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Python\test\t1.py", line 18, in <module>
player_card.append(random.sample(list(cards.keys),1))
TypeError: 'builtin_function_or_method' object is not iterable chinajz 发表于 2023-1-9 14:42
Traceback (most recent call last):
File "C:%users\Administrator\Desktop\Python\test\t1.py", lin ...
这个bug我也发现了,但是我在网上查了一堆资料,都没发现我哪里错了,网上大多数都是说这是由于python的内置函数忘了加括号,但我是检查了n遍,就是没发现哪里没有括号,有大佬会的能不能帮我修改一下{:10_254:} AhrimanSefid 发表于 2023-1-9 16:05
这个bug我也发现了,但是我在网上查了一堆资料,都没发现我哪里错了,网上大多数都是说这是由于python的 ...
keys后面没加括号 tommyyu 发表于 2023-1-10 18:09
keys后面没加括号
感谢{:5_111:}
修改后的代码:
import random
cards = {"A":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"J":0.5,"Q":0.5,"K":0.5,"Little Joker":0.5,"Big Joker":0.5}
player = True
player_card = []
player_card_number = []
computer = True
computer_card = []
computer_card_number = []
print("目前有这些卡牌:")
for item in cards.keys():
print(item)
for i in range(5):
player_card.append(random.sample(list(cards.keys()),1))
player_card_number.append(player_card)
computer_card.append(random.sample(list(cards.keys()),1))
computer_card_number.append(computer_card)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
print("玩家的牌是:",player_card)
print("玩家总共有",str(player_number_total),"点")
print("电脑的牌是:",computer_card)
print("电脑总共有",str(computer_number_total),"点")
if player_number_total > 10.5:
print("你被淘汰了哟")
player = False
else:
pass
if computer_number_total > 10.5:
print("电脑被淘汰了")
computer = False
else:
pass
if player == True and computer == True:
print("你们还可以继续游戏")
if player_number_total != 10.5 and computer_number_total != 10.5:
player_ask_number = int(input("你想要再抽几张牌?(1~4)"))
computer_ask_number = random.randint(1,4)
for i in range(player_ask_number):
player_card.append(random.sample(list(cards.keys()),1))
player_card_number.append(player_card)
for i in range(computer_ask_number):
computer_card.append(random.sample(list(cards.keys()),1))
computer_card_number.append(computer_card)
player_number_len = len(player_card_number)
computer_number_len = len(computer_card_number)
player_number_total = player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number+player_card_number
computer_number_total = computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number+computer_card_number
if player_number_total > 10.5 and computer_number_total > 10.5:
print("都没有赢哟,再来一局吧")
elif player_number_total <= 10.5 and computer_number_total > 10.5:
print("哈,你赢了,祝贺")
elif player_number_total > 10.5 and computer_number_total <= 10.5:
print("电脑赢了,继续加油")
else:
if player_number_total > computer_number_total:
print("哈,你赢了,祝贺")
elif player_number_total < computer_number_total:
print("电脑赢了,继续加油")
else:
print("平局哟,再来一局吧")
elif player_number_total == 10.5 and computer_number_total != 10.5:
print("哈,你赢了,祝贺")
elif player_number_total != 10.5 and computer_number_total == 10.5:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
elif player == True and computer == False:
print("哈,你赢了,祝贺")
elif player == False and computer == True:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
页:
[1]