Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 骰子扑克计分系统(功能型)_Python_Nonetype - Fatal编程技术网

Python 骰子扑克计分系统(功能型)

Python 骰子扑克计分系统(功能型),python,nonetype,Python,Nonetype,所以在我的编码课上,我们需要做一个“骰子扑克”游戏。我们需要实施一个评分系统,但是,我的系统不断返回“无”,因此,当我想将累积分数添加到100的基本分数时,会出现问题,因为无法添加非类型和整数。我知道我需要修复导致无的任何原因,但我不确定如何修复。我相信问题可能出在“得分”功能中,但可能更多的是隐藏在“骰子游戏”功能的后面部分(在“选择最后一卷”或“得分输出注释”之后)。我对编码非常陌生,在看了几个小时之后,我真的不确定我在看什么。非常感谢你的帮助 基于文本的骰子游戏 scoring()和num

所以在我的编码课上,我们需要做一个“骰子扑克”游戏。我们需要实施一个评分系统,但是,我的系统不断返回“无”,因此,当我想将累积分数添加到100的基本分数时,会出现问题,因为无法添加非类型和整数。我知道我需要修复导致无的任何原因,但我不确定如何修复。我相信问题可能出在“得分”功能中,但可能更多的是隐藏在“骰子游戏”功能的后面部分(在“选择最后一卷”或“得分输出注释”之后)。我对编码非常陌生,在看了几个小时之后,我真的不确定我在看什么。非常感谢你的帮助

基于文本的骰子游戏
scoring()
numcore()
中的返回语句具有错误的缩进。
scoring()
numcore()
中的返回语句具有错误的缩进。
from random import randint

def rollFiveDie():

 allDie = []
 for x in range(5):
    allDie.append(randint(1,6))

 return allDie

def outputUpdate(P, F):

  print(P)
  print(F)

def rollSelect():

  rollSelected = input("Which die would you like to re-roll? (Choose 1, 2, 3, 4 and/or 5 from the list)   ")
  print("  ")
  selectList = rollSelected.split()

  return selectList

def rollPicked(toRollList, diceList):

  for i in toRollList:
      diceList[int(i) - 1] = randint(1,6)

def scoring(dList):

  counts = [0] * 7
  for value in dList:
      counts[value] = counts[value] + 1

  if 5 in counts:
      score = "Five of a Kind", 30
  elif 4 in counts:
      score = "Four of a Kind", 25
  elif (3 in counts) and (2 in counts):
      score = "Full House", 15
  elif 3 in counts:
      score = "Three of a Kind", 10
  elif not (2 in counts) and (counts[1] == 0 or counts[6] == 0):
      score = "Straight", 20
  elif counts.count(2) == 2:
      score = "Two Pair", 5
  else:
      score = "Lose", 0

      return score

def numScore(diList):

  counts = [0] * 7
  for v in diList:
    counts[v] = counts[v] + 1

  if 5 in counts:
      finScore = 30
  elif 4 in counts:
      finScore = 25
  elif (3 in counts) and (2 in counts):
      finScore = 15
  elif 3 in counts:
      finScore = 10
  elif not (2 in counts) and (counts[1] == 0 or counts[6] == 0):
      finScore = 20
  elif counts.count(2) == 2:
      finScore = 5
  else:
      finScore = 0

      return finScore

def printScore(fscore):
  print(fscore)
  print("  ")


 def diceGame():

  contPlaying = True
  while contPlaying:

      playPoints = 30

      if playPoints > 9:
          playPoints -= 10

      else:
          print("No more points to spend. Game Over.")
          contPlaying = False

      playing = input("Would you like to play the Dice Game? (Answer 'y' or 'n'):  ")
      print('  ')

      if playing == 'y':

          #First Roll
          fiveDie = rollFiveDie()

          outputUpdate("Your roll is...", fiveDie)

           #Choosing Second Roll/Second Roll execution
          pickDie = input("Which die would you like to re-roll? (Choose 1, 2, 3, 4 and/or 5 from the list)   ")
          print("   ")
          pickDie = pickDie.split()

          rollPicked(pickDie, fiveDie)

          outputUpdate("Your next roll is...", fiveDie)

          #Choosing Last Roll
          pickDie = rollSelect()

          rollPicked(pickDie, fiveDie)

          outputUpdate("Your final roll is...", fiveDie)

          #Scoring output
          scoring(fiveDie)

          finalScore = numScore(fiveDie)

          playPoints += finalScore

          print(playPoints)

      else:

          contPlaying = False
def main():

  diceGame()

main()