NotaGoodProgrammer
NotaGoodProgrammer

Reputation: 61

Python duplicat input request

I am working on a large program to do conversions of imperial and metric measurements. I have started with miles and kilometres and have run into a problem with the first question to be asked. I am receiving a duplicated request for the first selected question, and I have a secondary issue of both the request for the imperial and metric question to be asked. I should only be asked for either miles or kilometre, not both.

The only way to end the repeated question issue is to remove the quotation marks around the index number I select in the question, as seen in def processing function, if choice == "1":, the corresponding question is repeated.

def main():

    distance_intro()
    choice = question_m_i()
    processing(choice)
    distM = metric()
    distK = imperial()
    miles_to_Imperial(distM)
    miles_to_Metric(distM)
    kilometer_to_Metric(distK)
    kilometer_to_Imperial(distK)
    specials(distK, distM)


def distance_intro():
    print()
    print()
    dist = 0
    print("This program will convert metric into \
        imperial or the inverse.\n" \
    "Please do not use a comma")
    print()

def question_m_i():

    while True:

        choice = ()
        print("Please choose a function:")
        print("        1, for Metrics;")
        print("        2, for Imperial;")

        choice = input("--> ", )

        if choice[0] >= "1" and choice[0] <= "2" and len(choice) == 1:
            break
            print("Choice must be, between 1-2, not ", choice + ".")
            print("Try again.")
            print()

    return choice

def processing(choice):

    for garbage in choice:
        if choice[0] == "1":
            metric()

    else:
        if choice[0] == "2":
            imperial()

def metric():
    distM = input("Please enter a distance for Miles: ")
    print()

    distM = float(distM)

    return distM

def imperial(): 
    distK = input("Please enter a kilometre distance for its conversion: ")
    print()

    distK = float(distK)

    return distK

I have tried using a number of different methods to code this program so that I only receive a request for miles or kilometres. My results remain such that the first question asked is repeated and then the second question for the other measurement is asked as well. The program should only ask for either miles or kilometre, based upon the selected function.

Below is the print out I receive. I would like to know where my mistake is, so to correct it.

This program will convert metric into imperial or the inve Please do not use a comma

Please select one of the below measurements

1 for Metric, or 2 for Imperial --> 1

Please enter a distance for Miles: 1

Please enter a distance for Miles: 1

Please enter a kilometre distance for its conversion: 2

Do any of you have any idea of how to fix this?

Upvotes: 0

Views: 52

Answers (1)

PatTheProgrammer
PatTheProgrammer

Reputation: 81

I noticed eval(list_of_measurements[int(choice_m_i)-1]) in the question_m_i() function. This has no purpose, it is not assigned to a variable or printed. It's assigned in main(), when metric() is first called.

Upvotes: 1

Related Questions