我的第二到几天,小时,分钟,秒计算器有几个问题
因此,我正在尝试制作一个计算器,该计算器可以显示输入秒的时间,小时,分钟和几秒钟。我想隐藏0s,例如) 0天,0小时, 2分钟23秒 我可以完成它们,但是有两个大问题...
- 每当我输入3600,ir 60之类的数字时,该程序都会返回而没有任何消息。.
- 每当我尝试删除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...
- whenever I input numbers like 3600, ir 60, the program just returns to start without any messages..
- 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 技术交流群。

不要将
打印(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 anelse
statement! Just remove theelse
statement and use theprint
command no matter what.