loops.py सम्पादन

# This program displays a temperature conversion table showing Fahrenheit
# temperatures from 0 to 100, in increments of 10, and the corresponding
# Celsius temperatures using While, For, and Do loops.

def while_loop():
    print("F°    C°")
    f = 0
    while f <= 100:
        c = (f - 32) * 5 / 9
        print(str(f) + " = " + str(c))
        f += 10

def for_loop():
    print("F°    C°")
    for f in range(0, 100 + 1, 10):
        c = (f - 32) * 5 / 9
        print(str(f) + " = " + str(c))

def do_loop():
    print("F°    C°")
    f = 0
    while True:
        c = (f - 32) * 5 / 9
        print(str(f) + " = " + str(c))
        f += 10
        if not(f <= 100): 
            break
        
def main():
    while_loop()
    for_loop()
    do_loop()

main()

कोशिश करो सम्पादन

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

यह भी देखें सम्पादन