【发布时间】:2015-04-25 20:38:47
【问题描述】:
我正在尝试在自己思考与我相关的项目和利用 teamtreehouse 之间学习 Python,尽管它进展缓慢。
我正在尝试查找有关如何使 python 3.3.2 for 循环从值 0 运行直到用户输入可变小时的值的教程。到目前为止,我只是在运行此代码时遇到错误。我没有成功找到涵盖这种方法的教程。
下面的教程似乎涵盖了从零开始,然后通过打印列表/字典的值运行 http://www.python-course.eu/python3_for_loop.php
本教程也是如此 http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3/For_Loops
这让我开始思考是否不可能,而我需要研究/学习其他循环?
#//////MAIN PROGRAM START//////
#//////VARIABLE DECLARATION//////
speedMPH=0
timeTraveling=0
hours=1
distanceTraveled=0
#//////VARIABLE DECLARATION//////
#//////USER INPUT FUNCTION//////
def userInput():
speedMPH=int(input("Please provide the speed the vehicle was going in MPH."))
hours=int(input("Please provide the number of hours it has been traveling in hours."))
#////////////////testing variable values correct////////////////
# print(speedMPH)
# print(hours)
# print(distanceTraveled)
#////////////////testing variable values correct////////////////
#//////USER INPUT FUNCTION//////
print('Distance Traveled\t\t\t' + 'Hours')
for i in range(1, hours + 1):
distanceTraveled=0
distanceTraveled = speedMPH * i
print(distanceTraveled, '\t\t\t\t\t', i)
#//////CALLING FUNCTION//////
userInput()
#//////CALLING FUNCTION//////
【问题讨论】:
-
抱歉 Padraic 我不知道我是怎么忘记了最重要的部分。我对其进行了编辑以包含它。
-
速度和时间应该从哪里来?
-
感谢 Padraic 纠正我的变量/语法错误。我现在已经更新了。不过,我在运行 for 循环时仍然遇到问题。
标签: python loops for-loop python-3.3