这是我的密码code

__author__ = 'Jared Reabow'

__name__ = 'Assignment 2 Dice game'

#Date created: 14/11/2014

#Date modified 17/11/2014

#Purpose: A game to get the highest score by rolling 5 virtual dice.

import random

#pre defined variables

NumberOfDice = 5 #this variable defined how many dice are to be rolled

def rollDice(NumberOfDice):

dice = [] #this is the creation of an unlimited array (list), it containes the values of the 5 rolled dice.

RunCount1 = 1 #This defines the number of times the first while loop has run

while RunCount1 <= NumberOfDice:

#print("this loop has run " , RunCount1 , " cycles.") #this is some debugging to make sure how many time the loop has run

TempArrayHolder = random.randint(1,6) #This holds the random digit one at a time for each of the dice in the dice Array.

dice.append(TempArrayHolder) #this takes the TempArrayHolder value and feeds it into the array called dice.

RunCount1 += 1 #this counts up each time the while loop is run.

return dice

rollDice(NumberOfDice)

dice = rollDice(NumberOfDice)

print(dice,"debug") #Debug to output dice array in order to confirm it is functioning

def countVals(dice,NumberOfDice):

totals = [0]*6 #this is the creation of a array(list) to count the number of times, number 1-6 are rolled

#print(dice, "debug CountVals function")

SubRunCount = 0

while SubRunCount < NumberOfDice:

totals[dice[SubRunCount -1] -1] += 1 #this is the key line for totals, it takes the dice value -1(to d eal with starting at 0) and uses it

#to define the array position in totals where 1 is then added.

#print(totals)

SubRunCount += 1

return totals

countVals(dice,NumberOfDice)

totals = countVals(dice,NumberOfDice)

print("totals = ",totals)

缩进可能有点错误,我是新手stackoverflow。

我在标题中指出的问题是,无论是否被调用,这两个函数都将运行,但如果被调用,它们将运行两次。在

我把括号去掉了:

^{pr2}$

所以就是这样dice = rollDice

会解决问题,在某种程度上,它做了一些事情,但不是我想要的。

如果我这样做,它会输出 debug

而不是运行这个函数,所以我被困在这里。在

如果能详细解释一下发生了什么事,我将不胜感激?在

更新:我错误地调用了函数两次。

我想我需要先运行它,然后才能使用它的返回输出,但是在代码中使用它时却不会这样做。在

python函数被调用才能执行吗_python3x函数在不被调用的情况下运行相关推荐

  1. Python之多线程:python多线程设计之同时执行多个函数命令详细攻略

    Python之多线程:python多线程设计之同时执行多个函数命令详细攻略 目录 实现功能 采取方法 应用场景 实现功能 同时执行多个函数命令 采取方法 T1.单个实现 import threadin ...

  2. Ajax异步请求(重渲染DOM元素时,如何自动调用并执行JS自定义函数【含代码】)- 案例篇

    文章目录 Ajax异步请求(重渲染DOM元素时,如何自动调用并执行JS自定义函数[含代码])- 案例篇 效果截图: 重要代码: 附:全部HTML代码: Ajax异步请求(重渲染DOM元素时,如何自动调 ...

  3. python win+r时不成功_Win与R(不使用Anaconda的情况下)

    配置R的路径信息: Path:添加R.dll的路径 如:E:\software\R\R-3.5.1\bin\x64 R_HOME:R的安装路径 如:E:\software\R\R-3.5.1\bin ...

  4. python离线安装第三方库whl_详细说明如何在pycharm不联网的情况下,离线安装第三方库及依赖包(如sklearn)...

    1.安装目标库 1.首先,选择你要导入的库文件,如seaborn库 下载网站: https://pypi.org/ 或https://www.lfd.uci.edu/~gohlke/pythonlib ...

  5. python3发送https请求_关于python 3.x:如何在不引起python3的SSL证书错误的情况下将POST请求发送到https...

    事情是这样的,我一直在尝试从python内部将POST请求发送到LOGIN到我的大学wifi页面,但是却收到SSL证书错误. POST请求在chrome的POSTMAN扩展中可以正常工作. 这是我使用 ...

  6. python读取文件编码错误_Python 读取文本文件编码错误解决方案(未知文本文件编码情况下解决方案)...

    很多情况下我们是这样读取文本文件的: with open(r'F:\.Python Project\spidertest1\test\pdd凉席.txt', 'r') as f: text = f.r ...

  7. qt执行命令行失败_QT缺少 qtcore4.dll,debug下运行不成功

    刚装QT的时候,好像我的环境变量没有设置好,哎,.隐患终于爆发了.在VS下运行成功的QT程序,然后点击Debug下的.exe,老提示缺少Qtcore4.dll,当时正郁闷之极,忘了怎样在网页上查找,只 ...

  8. python调用php命令行,python调用php函数 python怎样调用php文件中的函数详解

    前言 python调用php代码实现思路:php文件可通过在terminal中使用php命令行进行调用,因此可使用python开启子进程执行命令行代码.函数所需的参数可通过命令行传递. 测试环境 1. ...

  9. python echo函数_python如何调用php文件中的函数详解

    前言 python调用php代码实现思路:php文件可通过在terminal中使用php命令行进行调用,因此可使用python开启子进程执行命令行代码.函数所需的参数可通过命令行传递. 测试环境 1. ...

最新文章

  1. 前沿 | 全球最具影响力开源数据库峰会开幕在即 阿里云精彩议题先睹为快
  2. nginx tomcat集群实现session共享
  3. wxWidgets:wxStdInputStream类用法
  4. scp和ssh如何连接指定端口的远程主机
  5. Activity——思维导图
  6. docker配置网易云镜像
  7. PHP实现电子商务网站
  8. nginx+rtmp(或http-flv)+ffmpeg搭建流媒体视频直播服务器
  9. IDEA单机,双人五子棋
  10. C语言制作扫雷游戏(结合图形库)
  11. hive和presto计算日期时间差
  12. 干货 | 数字经济创新创业——数字技术创造新经济
  13. caffe 中的损失函数分析
  14. 美国国家学术出版社所有PDF图书开放免费下载
  15. 第三方接口转换工具类
  16. 新开的淘宝店铺要怎么操作才能排名靠前?
  17. 华为平板如何换计算机的皮肤,走出护肤误区,华为镜子携手皮肤专家化解护肤难题...
  18. GEA 3.3 捕捉及处理错误
  19. 会计是怎样用计算机的,一种会计用计算机的制作方法
  20. iPhone X下界面满屏展示

热门文章

  1. micropython移植教程_【教程】智能编程T-Watch手表初试micropython之电子秤教程
  2. vector clone_Java Vector clone()方法与示例
  3. javafor循环打印图案_C程序使用循环打印盒子图案
  4. mcq 队列_MCQ | 基础知识 免费和开源软件| 套装3
  5. python中assert_在Python中带有示例的assert关键字
  6. 2万字!66道并发面试题及答案
  7. 漂亮又好用的Redis可视化客户端汇总
  8. C++总结篇(4)内存管理
  9. C语言最新知识整理(纯干货)
  10. CentOS 7 搭建swagger Api文档管理系统