Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Is there any way to convert pseudocode into python? Because I'm trying my best to convert this following pseudocode to python and I have no clue about it. Can anyone suggest to me some ways, so that I can able to convert it?

Following pseudo-code:

cost = value / 0.33;

write “It would cost $”+cost "to ship a car that cost $” +value+"  to Togo."

else if (option = 4)

cost = value / 0.17;

write “It would cost $”+cost "to ship a car that cost $” +value+"  to Kenya."

else if ( option = 5)

cost = value / 0.31;

write “It would cost $”+cost "to ship a car that cost $” +value+"  to Somalia."

else

write “This is not a valid selection” “Please try again.”

endif

Write “Vehicle price you entered:”, value

Write “Shipping cost:”, cost

Write “Would you like to choose another selection, Y=Yes or N=No.”

Get choice

End while

Write “Thank you our application.”

End main module

1 Answer

0 votes
by (26.4k points)

This code works and it won't catch any error conditions,

options = [

    {'vehicle': 'Car', 'destination': 'Ghana', 'coeff': 0.3},

    {'vehicle': 'Van', 'destination': 'Nigeria', 'coeff': 0.2},

    {'vehicle': 'Truck', 'destination': 'Togo', 'coeff': 0.33},

    {'vehicle': 'Van', 'destination': 'Kenya', 'coeff': 0.17},

    {'vehicle': 'Truck', 'destination': 'Somalia', 'coeff': 0.31},

]

while True:

    print("Vehicle Shipping Rates to Africa")

    for i, opt in enumerate(options):

        print("%i. %s to %s" % (i+1, opt['vehicle'], opt['destination']))

    option = options[int(raw_input("Enter the choice:"))]

    value = float(raw_input("Enter the car price:"))

    cost = value / option['coeff']

    print("It would cost $%s to ship a %s that cost $%s to %s." % (cost, option['vehicle'], value, option['destination']))

    print("Vehicle price you entered: %s" % value)

    print("Shipping cost: %s" % cost)

    again = raw_input("Would you like to choose another selection, Y=Yes or N=No.")

    if again.lower() == 'n':

        break

print("Thank you our application.")

Wanna become an Expert in python? Come & join: Python Certification Course

Related questions

0 votes
4 answers
0 votes
2 answers
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...