Anyone know basic python programming?

Discussion in 'OT Technology' started by manchild, Oct 1, 2008.

  1. manchild

    manchild OT Supporter

    Mar 16, 2005
    Likes Received:
    This is my first project using Python, we had to make a "Traveler's Widget" that does time conversion from East Coast US to UK time and reverse, *F to *C and reverse, and then translate 5 UK slang words to US English.

    I've done the program, and it works, for the most part. It's done using a Text User Interface, and I can't figure out how to put an error message when it does something it shouldn't.

    This is the basic interface.
    Traveler's Widget
    1-Convert US time to UK time
    2-Convert UK time to US time
    3- Convert Fahrenheit to Celsius
    4-Convert Celsius to Fahrenheit
    5-Translate simple UK slang
    6- Exit
    Enter operation:

    I need to figure out how to get an error message (such as "Operation not recognized"), if you enter, say, "9" at the first user input.

    The other bug I get is when doing convert UK time to US time, if you put in 500 it gives you 0 instead of 1200. (It's on a 12 hour time scale, but colons weren't used.

    I can't find anywhere to upload it but here['s the text of the program, I style is probably terrible.

    def Travelers_Widget():
    print "Traveler's Widget"
    print "1-Convert Bloomington, IN time to UK time"
    print "2-Convert UK time to Bloomington, IN time"
    print "3-Convert Fahrenheit to Celsius"
    print "4-Convert Celsius to Fahrenheit"
    print "5-Translate simple UK slang"
    print "6-Exit"

    operation_number=(raw_input("Enter Operation: "))

    if operation_number=="1":
    while True:
    US_time=int(raw_input('Enter Bloomington, IN time: '))
    print "Time in UK is", (US_time + 500)%1200

    if operation_number=="2":
    while True:
    UK_time=int(raw_input('Enter UK time: '))
    print "Time in Bloomington, IN is", (UK_time - 500)%1200

    if operation_number=="3":
    while True:
    F_temp=int(raw_input('Enter Degrees Fahrenheit: '))
    print "Degrees Celsius are", (F_temp - 32) / 1.8

    if operation_number=="4":
    while True:
    C_temp=int(raw_input('Enter Degrees Celsius: '))
    print "Degrees Fahrenheit are", (C_temp - 32) / 1.8

    if operation_number=="5":
    while True:
    print "UK words are:"
    print "bladdered"
    print "nick"
    print "owt"
    print "porkies"
    print "spend a penny"
    uk_word=(raw_input('Enter UK word: '))
    if uk_word=="bladdered":
    print "US word is drunk"
    elif uk_word=="nick":
    print "US word is steal"
    elif uk_word=="owt":
    print "US word is anything"
    elif uk_word=="porkies":
    print "US word is lies"
    elif uk_word=="spend a penny":
    print "US word is go to the restroom"

    if operation_number=="6":
    print "DONE!"


  2. zanyspy_dude

    zanyspy_dude King of teh n00bz

    Aug 29, 2002
    Likes Received:
    Indianapolis, IN
    my god. what class is this?

    I'm assuming that UK is +5 from bloomington? So why wouldn't the result be 0 when you subtract 5?

    500 - 500 % 1200 = 0 % 1200 = 0

Share This Page