कंप्यूटर प्रोग्रामिंग/कंडीशन/पाइथन3

विकिविश्वविद्यालय से

conditions.py[सम्पादन | स्रोत सम्पादित करें]

# This program asks the user to select Fahrenheit or Celsius conversion
# and input a given temperature. Then the program converts the given
# temperature and displays the result.

def to_celsius():
    print("Enter Fahrenheit temperature:")
    f = float(input())
    c = (f - 32) * 5 / 9
    print(str(f) + "° Fahrenheit is " + str(c) + "° Celsius")

def to_fahrenheit():
    print("Enter Celsius temperature:")
    c = float(input())
    f = c * 9 / 5 + 32
    print(str(c) + "° Celsius is " + str(f) + "° Fahrenheit")

def if_else():
    print("Enter F to convert to Fahrenheit or C to convert to Celsius:")
    choice = input()
    if choice == "C" or choice == "c":
        to_celsius()
    elif choice == "F" or choice == "f":
        to_fahrenheit()
    else:
        print("You must enter C to convert to Celsius or F to convert to Fahrenheit!")

def main():
    if_else()
    
main()

कोशिश करो[सम्पादन | स्रोत सम्पादित करें]

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें[सम्पादन | स्रोत सम्पादित करें]