probably a simple fix but i just cant work it out,
Basically this is a little program I made to calculate the hours I've worked in a day in decimal format, (becasuse I have to do it like that for my timesheet for work) works perfectly fine, but I decided to add in a feature where if I enter restart at anytime the whole program restarts.
I tried calling Time within Time but doing that restarts but then finishes the original after starting over. I also tried making a Restart function that calls Time and then call Restart but that didn't work either.
So I wanted to break out of them both and call the program again, is this possible or not?
def Time():
clear()
def is_valid_hours():
while True:
h=input("Hour: ")
if h=="restart": return "yes" #this line doesnt work (tried break)
try:
h=int(h)
return h
except:
print("Please enter numbers!")
def is_valid_Minutes():
while True:
h=input("Minute: ")
if h=="restart": return "yes" # this is the other line (break tried)
try:
h=int(h)
return h
except:
print("Please enter numbers!")
print("Please use time in a 24hour clock format when using this calculator")
print("Please enter arrival time:")
arrivalTimeHours=is_valid_hours()
arrivalTimeMinutes=is_valid_Minutes()
print("Please enter length of lunch break: ")
lunchBreakHours=is_valid_hours()
lunchBreakMinutes=is_valid_Minutes()
print("Please enter desired leave time: ")
leaveTimeHours=is_valid_hours()
leaveTimeMinutes=is_valid_Minutes()
if arrivalTimeHours>0:
arrivalTimeHours=arrivalTimeHours*60
arrivalTime=arrivalTimeHours+arrivalTimeMinutes
if lunchBreakHours>0:
lunchBreakHours=lunchBreakHours*60
lunchBreak=lunchBreakHours+lunchBreakMinutes
if leaveTimeHours>0:
leaveTimeHours=leaveTimeHours*60
leaveTime=leaveTimeHours+leaveTimeMinutes
totalTimeMinutes=leaveTime-(arrivalTime+lunchBreak)
decimalTime=totalTimeMinutes/60
print("Your decimal time is "str(decimalTime))
newTime=input("Would you like to do a new time?: ")
return newTime.lower()
newTime=Time()
while newTime=="yes" or newTime=="ye" or newTime=="y" or newTime=="yah" or newTime=="yeah" or newTime=="yh":
newTime=Time()
input("Press enter to close")
EDIT: I did try doing this aswell, it didn't work either.
def Time():
clear()
notQuitting=True
while notQuitting==True:
def is_valid_hours():
while True:
h=input("Hour: ")
if h=="restart":
notQuitting=False
return "yes"
try:
h=int(h)
return h
except:
print("Please enter numbers!")
def is_valid_Minutes():
while True:
m=input("Minute: ")
if m=="restart":
notQuitting=False
return "yes"
try:
m=int(m)
return m
except:
print("Please enter numbers!")
#rest of code