简体   繁体   中英

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.

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.

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 = 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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