Reputation: 55
I am super new to Python. I've been taking a Python Course on Coursera and fooling around with a little bit of code. Prior to today I was doing the class on a chromebook, and therefore using the sandbox tool provided. I've purchased an actual PC to download python since. I wrote a little code that was working just fine in the sandbox tool, but when I enter it into python it keeps booting me out. Can anyone spot anything obviously wrong with my code that I should change?
It should take an input of a date, exercise, and then keep looping through asking you about your sets and reps, saving results as tuples in a dictionary, until you enter 0, where it exits the loop, and prints the results. Stumped!
dt = input("Date:")
ex = input("Exercise:")
d = dict()
set = 0
while True:
wrk = input("Insert as Reps x Weight: ")
if wrk == "0":
break
set = set + 1
d[set] = wrk
print(dt)
print(ex)
print(d)
Upvotes: 0
Views: 140
Reputation: 472
Indentation is really important in Python since it uses whitespace to differentiate between blocks of code.
Here,
while
statement. Note that the indentation in the if
block remains the same. This is because we want break
to execute only if wrk
is 0.set+1
outside because the condition did not match and we wanted our program to keep running.python
dt = input("Date:")
ex = input("Exercise:")
d = dict()
set = 0
while True:
wrk = input("Insert as Reps x Weight: ")
if wrk == "0":
break
set = set + 1
d[set] = wrk
print(dt)
print(ex)
print(d)
This works as expected.
Upvotes: 1