好吧,我想做一個簡單的程序來測試我學習的東西有多好,我已經到了一個點,它變得非常大,因爲我想程序將數據存儲在部分(Day1,Day2 .... ect),所以我試圖分配它讀取當前日計數(Num_Days =),但它似乎並不喜歡這樣。我做了一個小測試循環,試着測試一下,如果我能做到這一點,即使邏輯看起來不錯,我也會陷入困境。我試圖做一些搜索,但因爲我不知道我想做甚麼叫我沒有得到很遠。我想要做的就是讓循環讀取Num_Days並給Days()計數並通過'n'將它分配給那一天。簡單的Python循環計數器問題
Num_Days = 0
Total = 0
Data = 0
Day1 = 0
Day2 = 0
Day3 = 0
def Start_Work(x):
while Num_Days < 3:
Num_Days += 1
print "This is Day:",Num_Days
n = Num_Days
Total = +20
Day(n) += Total
else:
print "failed"
x = str('start')
我也做了一個dpaste上它,因爲它是容易,我看它的方式,然後在全黑:http://dpaste.com/1398446/
爲了顯然清理,我失去了一些人的思維我只是試圖讓自己坐在一個單獨的循環中,我將要建立我正在嘗試使用的循環。這個程序運行的方式是我想要的,問題是如果我想讓它變大,它會變得很長。
NumDays = 0
TotalOut = 0
Day1Tot = 0
Day1_RepsCnt = 0
Day4 = 0
def Work_Out(x):
while x == 1: ##crunches
NumDays = 0
TotalOut = 0
Day1Tot = 0
Day1_RepsCnt = 0
Day1_WghtCnt = 0
Day4 = 0
while NumDays < 3:
Day1_Wght = float(raw_input("How much weight did you use?"))
Day1_Reps = float(raw_input("How many reps did you do?"))
Day1_Sets = float(raw_input("How many sets were done?"))
Day1 = Day1_Wght * Day1_Reps * Day1_Sets
NumDays += 1
print "Day:",NumDays
print "Your total output is:",Day1
Day1_RepsCnt += Day1_Reps
Day1_WghtCnt += Day1_Wght
Day1Tot += Day1
TotalOut += Day1
if NumDays == 3:
print "Your total output for 3 days is:",TotalOut
print "Lets increase the Weight to",(Day1_Wght + 10)
print "Increase the Weight for days 4-6"
while NumDays >= 3 and NumDays <6:
Day4_Wght = float(raw_input("How much weight did you use?"))
if Day4_Wght <= (Day1_WghtCnt/3):
print "You need to increase your total output, add 10 pounds."
break
Day4_Reps = float(raw_input("How many reps did you do?"))
Day4_Sets = float(raw_input("How many sets were done?"))
Day4 += Day4_Wght * Day4_Reps * Day4_Sets
NumDays += 1
print "Day:",NumDays
if Day4_Wght <= (Day1_WghtCnt/3):
print "Re-enter totals once you have added the additional weight."
else :
print "Your total output was:",Day4
while x == 2: ##Benching
NumDays = 0
TotalOut = 0
Day1Tot = 0
Day1_RepsCnt = 0
Day4 = 0
while NumDays < 3:
Day1_Wght = float(raw_input("How much weight did you use?"))
Day1_Reps = float(raw_input("How many reps did you do?"))
Day1_Sets = float(raw_input("How many sets were done?"))
Day1 = Day1_Wght * Day1_Reps * Day1_Sets
NumDays += 1
print "Day:",NumDays
print "Your total output is:",Day1
Day1_RepsCnt += Day1_Reps
Day1Tot += Day1
TotalOut += Day1
if NumDays == 3:
print "Your total output for 3 days is:",TotalOut
print "Lets increase the Reps to",(Day1_Reps + 10)
print "Increase reps for days 4-6"
while NumDays >= 3 and NumDays <6:
Day4_Wght = float(raw_input("How much weight did you use?"))
Day4_Reps = float(raw_input("How many reps did you do?"))
if Day4_Reps <= (Day1_RepsCnt/3):
print "You need to increase your total output, do 10 more Reps."
break
Day4_Sets = float(raw_input("How many sets were done?"))
Day4 += Day4_Wght * Day4_Reps * Day4_Sets
NumDays += 1
print "Day:",NumDays
if Day4_Reps <= (Day1_RepsCnt/3):
print "Re-enter totals once you have completed the additional reps."
else :
print "Your total output was:",Day4
print "Available work outs in this version: crunches, benching"
Input = raw_input("What type of Work Out did you do?")
if Input.lower() == str('crunches'):
Work_Out(1)
if Input.lower() == str('benching'):
Work_Out(2)
else:
print "Failed"
是的,我明白,這需要被清理,但我有什麼,我想扔那裏的東西,我想重新安排其他的想法,但現在它只是試圖找出如何我可以將其分爲週期週期和每週週期分解,所以我開始試圖通過一週的時間,並找出這將是非常困難的只是試圖超過2天,所以我把它分成兩部分,而不是6天。任何建議是值得歡迎的。
好吧,代碼採樣器似乎不喜歡我,對不起。請按照dpaste – Aoxx
刪除第一行開始處的''''字符(我會這樣做,但我不能進行小於6個字符的編輯) – fjarri
您的理解是,第(1)日'會改變變量'Day1'?如果是這樣,不,請閱讀數組。 – Malvolio