当前位置: 首页 > news >正文

大朗镇网站仿做重庆网上房地产查询

大朗镇网站仿做,重庆网上房地产查询,设计工作室名字大全,简单手工文章目录 问题1#xff1a;坐标轴及标签显示问题2#xff1a;赢得比赛的最佳项目并计数问题3#xff1a;21点游戏方法1#xff1a;把超过21点的最后记为0方法2#xff1a;把超过21点在最后进行判断方法3#xff1a;官方代码与方法2相似 问题1#xff1a;坐标轴及标签显示… 文章目录 问题1坐标轴及标签显示问题2赢得比赛的最佳项目并计数问题321点游戏方法1把超过21点的最后记为0方法2把超过21点在最后进行判断方法3官方代码与方法2相似 问题1坐标轴及标签显示 正如你所看到的他最近运气不佳。他想用一些精选的表情符号沿着在推特上发布这条消息但是就像现在看起来的那样他的追随者可能会觉得很困惑。他问你是否可以帮助他做出以下改变 添加标题“500次老虎机抽奖的结果” 使y轴从0开始。 将标签“Balance”添加到y轴 在调用typegraph之后您可以看到Jimmy的图是类型 matplotlib.axes._subplots.AxesSubplot 。嗯这是新的。通过调用dirgraph您会发现三个看起来很有用的方法.set_title、.set_ylim和.set_ylabel。 使用这些方法根据Jimmy的请求完成函数prettify_graph。我们已经为您检查了第一个请求设置标题。 记住如果你不知道这些方法的作用请使用help函数 .set_title设置标题.set_ylim设置y轴.set_ylabel设置y轴标签 def prettify_graph(graph):Modify the given graph according to Jimmys requests: add a title, make the y-axisstart at 0, label the y-axis. (And, if youre feeling ambitious, format the tick marksas dollar amounts using the $ symbol.)graph.set_title(Results of 500 slot machine pulls)# Complete steps 2 and 3 here # graph.set_title(Results of 500 slot machine pulls)graph.set_ylim(0)graph.set_ylabel(Balance)graph jimmy_slots.get_graph() prettify_graph(graph) graph额外好处您可以对y轴上的数字进行格式设置使它们看起来像美元金额吗例如200美元而不是200美元。 def prettify_graph(graph):graph.set_title(Results of 500 slot machine pulls)# Make the y-axis begin at 0graph.set_ylim(bottom0)# Label the y-axisgraph.set_ylabel(Balance)# Bonus: format the numbers on the y-axis as dollar amounts# An array of the values displayed on the y-axis (150, 175, 200, etc.)ticks graph.get_yticks()# Format those values into strings beginning with dollar signnew_labels [${}.format(int(amt)) for amt in ticks]# Set the new labelsgraph.set_yticklabels(new_labels)graph jimmy_slots.get_graph() prettify_graph(graph) graph问题2赢得比赛的最佳项目并计数 Luigi正试图进行分析以确定在Mario Kart赛道上赢得比赛的最佳项目。他有一些字典列表形式的数据看起来像… [ {‘name’: ‘Peach’, ‘items’: [‘green shell’, ‘banana’, ‘green shell’,], ‘finish’: 3}, {‘name’: ‘Bowser’, ‘items’: [‘green shell’,], ‘finish’: 1}, # Sometimes the racer’s name wasn’t recorded {‘name’: None, ‘items’: [‘mushroom’,], ‘finish’: 2}, {‘name’: ‘Toad’, ‘items’: [‘green shell’, ‘mushroom’], ‘finish’: 1}, ] “items”是参赛者在比赛中获得的所有能量提升物品的列表“finish”是他们在比赛中的位置1代表第一名3代表第三名等等。 他写了下面的函数来获取这样的列表并返回一个字典将每个条目映射到第一名完成者拾取的次数。 def best_items(racers):# 创建空字典用于存储第一名完成者拾取的次数winner_item_counts {}for i in range(len(racers)):# 对于列表中每个字典进行操作racer racers[i]# 如果是第一名if racer[finish] 1:# 获取第一名的项目for item in racer[items]:# 如果结果字典中没有该元素进行创建if item not in winner_item_counts:winner_item_counts[item] 0# 有该元素则次数加1winner_item_counts[item] 1# 如果名字未记录发出警告if racer[name] is None:print(警告{}/{}名字为空未记录 (racer {}).format((i1),len(racers),racer[name]))return winner_item_counts sample [{name: Peach, items: [green shell, banana, green shell,], finish: 3},{name: Bowser, items: [green shell,], finish: 1},{name: None, items: [mushroom,], finish: 2},{name: Toad, items: [green shell, mushroom], finish: 1}, ] best_items(sample)问题321点游戏 假设我们想创建一个新类型来表示21点中的手牌。我们可能想对这种类型做的一件事是重载比较运算符如和以便我们可以使用它们来检查一只手是否击败另一只手。如果我们能做到这一点那就太酷了 hand1 BlackjackHand([‘K’, ‘A’]) hand2 BlackjackHand([‘7’, ‘10’, ‘A’]) hand1 hand2 True 好吧我们不会在这个问题中完成所有这些定义自定义类有点超出了这些课程的范围但是我们要求您在下面的函数中编写的代码与我们定义自己的BlackjackHand类时必须编写的代码非常相似。(We我把它放在__gt__magic方法中为定义我们的自定义行为。 根据文档字符串填充blackjack_hand_greater_than函数体 方法1把超过21点的最后记为0 1、首先定义一个21点的计数函数BlackjackHand(hand) def BlackjackHand(hand):count 0A_count 0# 进行遍历如果为A,J,Q,K中的其中一个加各自对应的数# 若为1~10则加int(x)for x in hand:if x A:A_count A_count 1count count 11continueif (x J or x Q or x K):count count 10continueelse:count count int(x)# 判断 if A_count 0 and count 21:count countelif A_count 0 and count 21:count 0elif A_count 0 and count 21:count countelif A_count 0 and count 21:for i in range(A_count):count count - 10if count 21:count countif count 21:count 0return count# 测试 print(BlackjackHand([K])) print(BlackjackHand([3, 4])) print(BlackjackHand([10])) print(BlackjackHand([K, K, 2])) print(BlackjackHand([A, A, 9])) print(BlackjackHand([A, A, 9, 3])) print(BlackjackHand([9,Q, 8,A]))2、最终代码 def blackjack_hand_greater_than(hand_1, hand_2):Return True if hand_1 beats hand_2, and False otherwise.In order for hand_1 to beat hand_2 the following must be true:- The total of hand_1 must not exceed 21- The total of hand_1 must exceed the total of hand_2 OR hand_2s total must exceed 21Hands are represented as a list of cards. Each card is represented by a string.When adding up a hands total, cards with numbers count for that many points. Facecards (J, Q, and K) are worth 10 points. A can count for 1 or 11.When determining a hands total, you should try to count aces in the way that maximizes the hands total without going over 21. e.g. the total of [A, A, 9] is 21,the total of [A, A, 9, 3] is 14.Examples: blackjack_hand_greater_than([K], [3, 4])True blackjack_hand_greater_than([K], [10])False blackjack_hand_greater_than([K, K, 2], [3])Falseif BlackjackHand(hand_1) BlackjackHand(hand_2):return Trueelse:return Falsedef BlackjackHand(hand):count 0A_count 0for x in hand:if x A:A_count A_count 1count count 11continueif (x J or x Q or x K):count count 10continueelse:count count int(x)if A_count 0 and count 21:count countelif A_count 0 and count 21:count 0elif A_count 0 and count 21:count countelif A_count 0 and count 21:for i in range(A_count):count count - 10if count 21:count countif count 21:count 0return count方法2把超过21点在最后进行判断 1、首先定义一个21点的计数函数BlackjackHand(hand) def BlackjackHand(hand):count 0A_count 0for x in hand:if x A:A_count A_count 1count count 11continueif (x J or x Q or x K):count count 10continueelse:count count int(x)if A_count 0 and count 21:for i in range(A_count):count count - 10if count 21:count countif count 21:count countreturn count# 测试 print(BlackjackHand([K])) print(BlackjackHand([3, 4])) print(BlackjackHand([10])) print(BlackjackHand([K, K, 2])) print(BlackjackHand([A, A, 9])) print(BlackjackHand([A, A, 9, 3])) print(BlackjackHand([9,Q, 8,A]))超过21点不变等到最后进行判断为False 2、最终代码 def blackjack_hand_greater_than(hand_1, hand_2):如果hand_1打败hand_2返回True否则返回False。为了使hand_1打败hand_2以下条件必须成立—hand_1的总数不能超过21—hand_1的总和必须大于hand_2的总和或者hand_2的总和必须大于21手牌被表示为一张牌的列表。每张卡片由一个字符串表示。当把一手牌的总牌数加起来时带有数字的牌就会得到相应的点数。脸卡片“J”、“Q”和“K”值10分。“A”可以数1或11。当决定一手牌的总数时你应该尝试用下面的方法来计算a在不超过21的情况下最大化手牌总数。例如[A, A, 9]的总数是21[A, A, 9, 3]的总数是14。Examples: blackjack_hand_greater_than([K], [3, 4])True blackjack_hand_greater_than([K], [10])False blackjack_hand_greater_than([K, K, 2], [3])False if (BlackjackHand(hand_1)21) and (BlackjackHand(hand_1) BlackjackHand(hand_2)) or (BlackjackHand(hand_1)21 and BlackjackHand(hand_2)21):return Trueelse:return Falsedef BlackjackHand(hand):# 定义总数和A的数量count 0A_count 0# for x in hand:if x A:A_count A_count 1count count 11continueif (x J or x Q or x K):count count 10continueelse:count count int(x)# 判断 if A_count 0 and count 21:for i in range(A_count):count count - 10if count 21:count countif count 21:count countreturn count方法3官方代码与方法2相似 def hand_total(hand):Helper function to calculate the total points of a blackjack hand.total 0# 计算a的数量并在最后处理如何使用它们aces 0for card in hand:if card in [J, Q, K]:total 10elif card A:aces 1else:# Convert number cards (e.g. 7) to intstotal int(card)# At this point, total is the sum of this hands cards *not counting aces*.# 添加a现在把它们记为1。这是我们从这只手能得到的最小的总数total aces# 把a从1 “升级”到11只要它能帮我们接近21# without bustingwhile total 10 21 and aces 0:# Upgrade an ace from 1 to 11total 10aces - 1return totaldef blackjack_hand_greater_than(hand_1, hand_2):total_1 hand_total(hand_1)total_2 hand_total(hand_2)return total_1 21 and (total_1 total_2 or total_2 21)简化 if card in [J, Q, K]:
http://www.w-s-a.com/news/124073/

相关文章:

  • 哪些网站可以做房产推广垂直门户网站都有什么
  • 不得不知道的网站金石项目管理软件
  • 怎么恢复网站数据库网站开发作业代做
  • 哪里建设网站最好用中国第五冶金建设公司医院网站
  • 雄安网建 网站建设订餐网站建设
  • 广州视频网站建站公司网站 体系
  • 青浦门户网站网站推广烟台公司电话
  • 湖北荆门建设银行网站wordpress购物模板下载
  • 学ui+wordpress模板北京推广优化
  • 建分类网站得花多少钱深圳设计网站开发
  • 网站集群建设和网站集约化百度商桥怎么绑定网站
  • 青岛模板网站建设价格网络品牌网站建设
  • 网站建设的几大要素网站的做网站的公司
  • 怎么登陆自己的公司网站垂直电商网站建设
  • 温州微网站制作哪里有许昌网站建设哪家最好
  • 中国中小企业网站官网网页制作工具按其制作方式分 可以分为
  • 做资源下载网站违法吗河南企业做网站
  • 网站开发总体功能设计网站建设 北京昌平
  • 辽宁省高等级公路建设局网站书画院网站建设方案
  • 本地生活网站 源码重庆本地网站有哪些
  • 企业网站域名服务器国外html响应式网站
  • 东莞网站建设策划企业网站推广策划方法
  • 网站的图片怎么制作WordPress交互式网站
  • pc网站增加手机站什么专业学网页设计制作
  • 婚庆公司网站模板wordpress用什么框架
  • 高校网站建设的时效性长沙市网站建设
  • 合肥网站建设市场四川建设网官网住房和城乡厅官网官方
  • 天行健君子以自强不息网站建设江西网站做的好的企业文化
  • 建网站内容谷歌搜索引擎优化
  • 网站建设与管理案例教程第三版答案网站建设策划书范文六篇精选