# Details: Capture User input to calculate cost and print receipt # Create empty recedictionary to dynamically set the receipt attributes receipt = {} # Greeting and Company Name receipt['Company'] = input("Greetings, Enter Company Name: ") # Error Handling - using try except method to loop retries while True: try: # dictionary key will only accept integer value receipt['Cable'] = int(input('Enter Cable Needed in feet: ')) break except (ValueError, TypeError) as e: # listed each error type print("\nError Occurred") # visually Offset print(e) # Print system error msg print("Please enter a whole number only") # human readable error # Cost = 'cable (in ft)' * 0.87 rate = 0.87 receipt['Total_cost_USD'] = receipt['Cable'] * rate # Print: using regex format to parse key(a) value(b) print("\nReceipt Details:") print("\n".join("{}\t{}".format(a, b) for a, b in receipt.items())) print('Rate \t', rate)
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