Converting Pseudo Code To Python -
i trying convert pseudo code python. have no clue on how this. looks simple have no knowledge of python, making impossible me do. pseudo code:
main module declare option declare value declare cost while(choice ==’y’) write “vehicle shipping rates africa” write “1. car ghana” write “2. van nigeria” write “3. truck togo” write “4. van kenya” write “5. truck somalia” write “enter choice:” option write “enter car price:” value if ( option = 1) cost = value / 0.30; write “it cost $”+cost "to ship car cost $” +value+" ghana." else if (option = 2) cost = value / 0.20; write “it cost $”+cost "to ship car cost $” +value+" nigeria." else if ( option = 3) cost = value / 0.33; write “it cost $”+cost "to ship car cost $” +value+" togo." else if (option = 4) cost = value / 0.17; write “it cost $”+cost "to ship car cost $” +value+" kenya." else if ( option = 5) cost = value / 0.31; write “it cost $”+cost "to ship car cost $” +value+" somalia." else write “this not valid selection” “please try again.” endif write “vehicle price entered:”, value write “shipping cost:”, cost write “would choose selection, y=yes or n=no.” choice end while write “thank our application.” end main module
you should try code before posing on stack overflow. work won't catch 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 africa") i, opt in enumerate(options): print("%i. %s %s" % (i+1, opt['vehicle'], opt['destination'])) option = options[int(raw_input("enter choice:"))] value = float(raw_input("enter car price:")) cost = value / option['coeff'] print("it cost $%s ship %s cost $%s %s." % (cost, option['vehicle'], value, option['destination'])) print("vehicle price entered: %s" % value) print("shipping cost: %s" % cost) again = raw_input("would choose selection, y=yes or n=no.") if again.lower() == 'n': break print("thank our application.")
Comments
Post a Comment