我的第二到几天,小时,分钟,秒计算器有几个问题

发布于 01-21 12:35 字数 1300 浏览 4 评论 0原文

因此,我正在尝试制作一个计算器,该计算器可以显示输入秒的时间,小时,分钟和几秒钟。我想隐藏0s,例如) 0天,0小时, 2分钟23秒 我可以完成它们,但是有两个大问题...

  1. 每当我输入3600,ir 60之类的数字时,该程序都会返回而没有任何消息。.
  2. 每当我尝试删除xx **。添加:.0f到{} s,我得到了ValueErrors ...

我几乎是一个初学者,老实说我已经尝试了整整一天,但我仍然在挣扎...如果您能告诉我怎么了,我会很感激。

while 1:
try:
    totsec=float(input("Type desired seconds : "))#Input seconds
    if(totsec%1!=0):#Bact to input if input is not decimal
        print("Can't calculate miliseconds...")
        continue
    if(totsec<0):#Bact to input if it is negative number
        print("Negative seconds...")
        continue
    if(totsec==0):#Back to input if it's 0
        print("umm... 0 second.")
        continue
    day=totsec//86400
    hour=(totsec-86400*day)//3600
    min=(totsec-86400*day-3600*hour)//60
    sec=totsec-86400*day-3600*hour-min*60
    #
    dayout,hourout,minout,secout=f'{day}Day, ',f'{hour}Hour, ',f'{min}Minute, ',f'{sec}second'
    if(day==0):#So I don't see 0 day
        dayout=str()
    if(hour==0):
        hourout=str()
    if(min==0):
        minout=str()
    if(sec==0):
        secout=str()
    else:
        print(f'{dayout}{hourout}{minout}{secout}!')
    continue
except ValueError:
    print("Its not a number...")#if input isn't a float number
    continue

So I am Trying to make a calculator that can show how much days, hours, minutes, and seconds the input seconds are. And I wanted to hide the 0s in eg)0 days, 0 hours, 2 minutes, 23 seconds
I could get them done, but there are two big problems...

  1. whenever I input numbers like 3600, ir 60, the program just returns to start without any messages..
  2. Whenever I try to remove xx**.0**, and add :.0f to the {}s, I get ValueErrors...

Im pretty much a beginner and honestly I tried for a whole day but Im still struggling... would appreciate it if you can tell me whats wrong..

while 1:
try:
    totsec=float(input("Type desired seconds : "))#Input seconds
    if(totsec%1!=0):#Bact to input if input is not decimal
        print("Can't calculate miliseconds...")
        continue
    if(totsec<0):#Bact to input if it is negative number
        print("Negative seconds...")
        continue
    if(totsec==0):#Back to input if it's 0
        print("umm... 0 second.")
        continue
    day=totsec//86400
    hour=(totsec-86400*day)//3600
    min=(totsec-86400*day-3600*hour)//60
    sec=totsec-86400*day-3600*hour-min*60
    #
    dayout,hourout,minout,secout=f'{day}Day, ',f'{hour}Hour, ',f'{min}Minute, ',f'{sec}second'
    if(day==0):#So I don't see 0 day
        dayout=str()
    if(hour==0):
        hourout=str()
    if(min==0):
        minout=str()
    if(sec==0):
        secout=str()
    else:
        print(f'{dayout}{hourout}{minout}{secout}!')
    continue
except ValueError:
    print("Its not a number...")#if input isn't a float number
    continue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈场末日恋爱2025-01-28 12:35:37

不要将打印(f'{dayout} {hourout} {minout} {minout} {secout}!')命令在else> else语句的正文中!只需删除else语句,然后使用print命令,无论如何。

Don't put the print(f'{dayout}{hourout}{minout}{secout}!') command in the body of an else statement! Just remove the else statement and use the print command no matter what.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文