Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on pressing enter
#1
Hi All.

I am new to python coding.
I am trying to get 4:0:0 hours count down by just entering "4 enter" and "enter for 0" then "enter for 0" again.
Or 0:5:0 for 5 Minutes instead of Actually entering 0 5 0
What I cannot get my head round is how to stop this error from incurring when I just hit enter for 0.

What have I missed or doing wrong.
Thanks.

Traceback (most recent call last):
File "/home/david/projects/Python-Files/Power_Supply/Count_Down_Timer.py", line 17, in <module>
minz = int(input('Minutes: '))
File "<string>", line 0

^
SyntaxError: unexpected EOF while parsing

Here is the code.
#!/usr/bin/env python3

import time
import sys


print(' ')
print('Countdown Timer')
print(' ')
print(' ')
print(' ')

c = ':'

# Get the users input
hourz = int(input('Hours: '))
minz = int(input('Minutes: '))
secz = int(input('Seconds: '))

hour = int(hourz)
minutes = int(minz)
seconds = int(secz)

while hour > -1:
    while minutes > -1:
        while seconds > 0:
            seconds = seconds - 1
            time.sleep(1)
            sec1 = ('%02.f' % seconds)  # format
            min1 = ('%02.f' % minutes)
            hour1 = ('%02.f' % hour)
            sys.stdout.write('\r' + str(hour1) + c + str(min1) + c + str(sec1))

        minutes = minutes - 1
        seconds = 60
    hour = hour - 1
    minutes = 59

print(' ')
print(' ')
print('Countdown Complete.')
time.sleep(5)
Reply
#2
Hard to tell because we don't get to see where error is coming from.
Code above has no error.

Best guess is line 17 in some module. You forgot the = sign between File and file path.
99 percent of computer problems exists between chair and keyboard.
Reply
#3
Are you saying you want to just press 'Enter' at the prompt and it will automatically infer that to be a zero? If so, you need to make some modifications, since just hitting 'Enter' crates an empty string. You might, for example do this:

hourz = input('Hours: ')
if hourz == '':
    hourz = int('0')
else:
    hourz = int(hourz)
Doing the same for minz and secz of course. Also note, in your original code and the example I've given, Hourz, minz and secz are already integers, so there really is no need for lines 20 thru 22 of the original code.

If I've misunderstood your question, perhaps you could explain a little more in depth.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
i think u converted each input twice with int()?
how about

hourz = input('Hours: ')

if not hourz:
 hourz = 0

hour = int(hourz)
the if not statement is to assign the input to 0 if u press enter without typing anything. do the same for minz and secz... i did this in python 2.7 just in case if code not working.
swallow osama bin laden
Reply
#5
(Feb-04-2018, 02:10 PM)ka06059 Wrote: i did this in python 2.7 just in case if code not working.

Also works in v3 :-)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
Quote:Also works in v3 :-)


just noticed your post after hittin the post reply button, almost similar LOL
swallow osama bin laden
Reply
#7
Dance Thanks to all.
it works fine now get no errors.

Thank you all again.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Build a matrix by pressing buttons of an interface in Tkinter which extract data from juandiegopulla 1 1,949 Sep-13-2021, 07:28 PM
Last Post: deanhystad
  performs the search without pressing enter or a key forumpy 3 1,961 Sep-22-2020, 11:26 PM
Last Post: deanhystad
  Pressing non-latin characters? Murlog 0 1,529 Jul-25-2020, 03:10 PM
Last Post: Murlog
  Py2EXE: terminal window closes after pressing ENTER peanutbutterjelly 1 5,094 May-06-2017, 07:13 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020