简体   繁体   English

使用If,Elif,else,使用公式代替print语句

[英]Using If, elif, else, using formulas instead of print statements

Someone in Stackoverflow answered my question which was brilliant, I need to replace the print statements with formulas. Stackoverflow中的某人回答了我的这个很棒的问题,我需要用公式替换print语句。

The reason for this so I can convert the output to hours, minutes, seconds. 这样做的原因是,我可以将输出转换为小时,分钟,秒。

Having multiple print statements and the formula included I can not separate them. 具有多个打印语句和包含的公式,我无法将它们分开。

I have three logics but just need to separate them into formulas like the print statement. 我有三种逻辑,但只需要将它们分成类似于print语句的公式即可。

Original program: 原始程序:

T17 = input('?')

if T17 < 0:
     print("LOCAL SIDEREAL TIME",T17 + 24)

elif T17 > 24:
    print("LOCAL SIDEREAL TIME",T17 - 24)

else:
        print("LOCAL SIDEREAL TIME",T17)

This is what I am trying to do. 这就是我想要做的。

T17 = input('?')

if T17 < 0:

 T17 + 24

elif T17 > 24:

 T17 - 24

else:

 print("LOCAL SIDEREAL TIME",T17)

It seems as though you meant to re-assign the calculations back to T17 : 似乎您打算将计算重新分配回T17

T17 = input('?')
if T17 < 0:
    T17 = T17 + 24
elif T17 > 24:
    T17 = T17 - 24

print("LOCAL SIDEREAL TIME", T17)

It looks like you're just trying to implement modulo : 看来您只是想实现模数

>>> -10 % 24
14
>>> 34 % 24
10
>>> 16 % 24
16

So : 因此:

t17 = t17 % 24

should do fine. 应该很好。

Finally, be sure to check Astropy if you're working on Astronomy with Python. 最后,如果您正在使用Python进行天文学研究,请确保检查Astropy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM