鱼C论坛

 找回密码
 立即注册
查看: 3855|回复: 16

成都趣题 第500001期 十点半

[复制链接]
发表于 2023-1-8 14:15:25 | 显示全部楼层 |阅读模式
本帖最后由 hveagle 于 2023-1-11 17:17 编辑

成都趣题 第500001期 十点半

游戏玩法:
十点半
参考答案:
游客,如果您要查看本帖隐藏内容请回复
[/hide]
奖励区:
名次第1名第2名第3名第4名第5名
等待着变成王者登上宝座~
语言
几楼
奖励展示+8荣誉7鱼币2贡献1技术值最佳答案展示+4荣誉4鱼币展示+3荣誉3鱼币展示+2荣誉展示

下一期
评分:
单选投票, 共有 5 人参与投票
80.00% (4)
20.00% (1)
0.00% (0)
0.00% (0)
0.00% (0)
您所在的用户组没有投票权限
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 16:10:06 | 显示全部楼层
本帖最后由 sfqxx 于 2023-1-8 16:14 编辑

@hveagle 在哪玩?怎么玩才能获得奖励?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-1-8 16:15:11 | 显示全部楼层
sfqxx 发表于 2023-1-8 16:10
@hveagle 在哪玩?怎么玩才能获得奖励?

发趣题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 16:16:52 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 16:17:07 | 显示全部楼层
那我要完了
我不会
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-1-8 16:18:28 | 显示全部楼层
sfqxx 发表于 2023-1-8 16:17
那我要完了
我不会

你发Scratch
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 16:19:08 | 显示全部楼层
代码怎么发(除图片)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 16:19:39 | 显示全部楼层
它是一块一块的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 18:40:05 | 显示全部楼层
然后我要做什么?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-1-8 19:08:21 | 显示全部楼层
zhangjinxuan 发表于 2023-1-8 18:40
然后我要做什么?

你报名了吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 19:42:03 | 显示全部楼层
没看懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 21:05:25 | 显示全部楼层
本帖最后由 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[i])
        computer_card.append(random.sample(cards.keys,1))
        computer_card_number.append(computer_card[i])

player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]
computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]

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[i+5])
                for i in range(computer_ask_number):
                        computer_card.append(random.sample(cards.keys,1))
                        computer_card_number.append(computer_card[i+5])
                player_number_len = len(player_card_number)
                computer_number_len = len(computer_card_number)
                player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]+player_card_number[5]+player_card_number[player_number_len]
                computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]+computer_card_number[5]+computer_card_number[computer_number_len]
                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:由于是直接写,没有调试,可能会报错,后面我会修改的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-8 21:13:57 | 显示全部楼层
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[i])
        computer_card.append(random.sample(list(cards.keys),1))
        computer_card_number.append(computer_card[i])

player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]
computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]

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[i+5])
                for i in range(computer_ask_number):
                        computer_card.append(random.sample(list(cards.keys),1))
                        computer_card_number.append(computer_card[i+5])
                player_number_len = len(player_card_number)
                computer_number_len = len(computer_card_number)
                player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]+player_card_number[5]+player_card_number[player_number_len]
                computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]+computer_card_number[5]+computer_card_number[computer_number_len]
                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("都没有赢哟,再来一局吧")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-9 14:42:11 | 显示全部楼层
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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-9 16:05:49 | 显示全部楼层
chinajz 发表于 2023-1-9 14:42
Traceback (most recent call last):
  File "C:%users\Administrator\Desktop\Python\test\t1.py", lin ...

这个bug我也发现了,但是我在网上查了一堆资料,都没发现我哪里错了,网上大多数都是说这是由于python的内置函数忘了加括号,但我是检查了n遍,就是没发现哪里没有括号,有大佬会的能不能帮我修改一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-10 18:09:36 | 显示全部楼层
AhrimanSefid 发表于 2023-1-9 16:05
这个bug我也发现了,但是我在网上查了一堆资料,都没发现我哪里错了,网上大多数都是说这是由于python的 ...

keys后面没加括号
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-10 20:13:22 | 显示全部楼层
tommyyu 发表于 2023-1-10 18:09
keys后面没加括号

感谢
修改后的代码:
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[i])
        computer_card.append(random.sample(list(cards.keys()),1))
        computer_card_number.append(computer_card[i])

player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]
computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]

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[i+5])
                for i in range(computer_ask_number):
                        computer_card.append(random.sample(list(cards.keys()),1))
                        computer_card_number.append(computer_card[i+5])
                player_number_len = len(player_card_number)
                computer_number_len = len(computer_card_number)
                player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]+player_card_number[5]+player_card_number[player_number_len]
                computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]+computer_card_number[5]+computer_card_number[computer_number_len]
                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("都没有赢哟,再来一局吧")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 11:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表