# gradient tools choice = None while choice != "0": print( """ Menu\n 1 = interpolate a level 2 = calculate a gradient press 3 = calculate a level using a gradient press 0 = quit """) choice = input("\nChoice: ") if choice == "1": menu = None while menu != "0": menu = input("\nPress enter to interpolate or 0 to return menu: ") if menu == "": spot1 = float(input("Enter spot 1: ")) spot2 = float(input("Enter spot 2: ")) distance1 = float(input("Distance between spots 1 and 2: ")) distance2 = float(input("Distance between spot 1 and interploted spot: ")) spot3 = round(((((spot2 - spot1) / distance1) * distance2) + spot1), 3) print("\nInterpolated spot is: ", spot3, "\n") elif menu == "0": print(" ") elif choice == "2": menu = None while menu != "0": menu = input("\nPress enter to calculate gradient or 0 to return to menu: ") if menu == "": spot1 = float(input("Enter spot 1: ")) spot2 = float(input("Enter spot 2: ")) distance1 = float(input("Distance between spots 1 and 2: ")) if spot1 >= spot2: gradient = round((1 / ((spot1 - spot2) / distance1)), 2) else: gradient = round((1 / ((spot2 - spot1) / distance1)), 2) print("\nThe gradient is 1 in", gradient) elif menu == "0": print("\n") elif choice == "3": menu = None while menu != "0": menu = input("\nPress enter to continue or 0 to return to menu: ") if menu == "": gradient1 = float(input("Required gradient is 1 in ")) gradient2 = 1 / gradient1 distance = float(input("Distance between spots: ")) spot1 = float(input("Enter fixed spot height: ")) fall = input("(R)ise or (F)all: ") if fall == "f": spot2 = round((spot1 -(gradient2 * distance)), 3) elif fall == "r": spot2 = round((spot1 +(gradient2 * distance)), 3) elif fall != "f" or "r": fall = input("(R)ise or (F)all: ") print("\nAdjusted spot height should be", spot2) elif menu == "0": print("\n") elif choice == "0": print("Good bye") input("Press enter to exit.")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question