简体   繁体   中英

How would I make it so I can enter what I want to use in lower and upper caps?. Example - sin/SIN, tan/TAN

import math

print("Trigonometry calculator")

trig_choices = "Sin", "Tan", "Cos"

trig_choices_pick = input("Choose (Sin,Cos,Tan): ")

if trig_choices_pick == "Tan":
    opposite_value = float(input("Opposite: "))
    adjacent_value = float(input("Adjacent: "))
    print(math.degrees(math.atan(opposite_value / adjacent_value)))

elif trig_choices_pick == "Sin":
    opposite_value = float(input("Opposite: "))
    hypotenuse_value = float(input("Hypotenuse: "))
    print(math.degrees(math.asin(opposite_value / hypotenuse_value)))

elif trig_choices_pick == "Cos":
    adjacent_value = float(input("Adjacent: "))
    hypotenuse_value = float(input("Hypotenuse: "))
    print(math.degrees(math.acos(adjacent_value / hypotenuse_value)))

To add onto the question, how would I be able to enter both the short version of "Cos" and the long version "Cosine"?

if trig_choices_pick[:3].lower() == "cos":
    # will match "COSINE", "cosine", "cos", etc
    ...

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