Write a function named take_input() that asks the user for the names (strings) of the owner and the company, and the names (strings), unit prices (floats), stock quantities (ints) of at least 3 products, and writes this information in a new text file using the following format. owner_name,company_name product1_name,product1_unitprice,product1_stock product2_name,product2_unitprice,product2_stock product3_name,product3_unitprice,product3_stock The name of this text file can be taken as an input parameter of your function or you can choose to use a pre-determined (fixed) name inside of this function. Your function must use exception handling to handle all possible run-time errors so that this function does not crash. Please enter your name >> Bond Hi Bond, please enter your company name >> Mart 007 Let's set up a sales menu for 'Mart 007'. Enter item 1's name >> Spiked Umbrella Enter item 1's unit price >> 7.25 Enter item 1's quantity >> 5 Enter item 2's name >> Voice Changer Enter item 2's unit price >> 5.5 Enter item 2's quantity >> 10 Enter item 3's name >> Spy Camera Enter item 3's unit price >> fifteen Price must be a number. Please enter again >> -15 Price must be positive. Please enter again >> 15 Enter item 3's quantity >> eight Stock must be a number. Please enter again >> -8 Stock must be positive. Please enter again >> 8 And the following will be written to the text file. Bond,Mart 007 Spiked Umbrella,7.25,5 Voice Changer,5.5,10
Write a function named take_input() that asks the user for the names (strings) of the owner
and the company, and the names (strings), unit prices (floats), stock quantities (ints) of at least
3 products, and writes this information in a new text file using the following format.
owner_name,company_name
product1_name,product1_unitprice,product1_stock
product2_name,product2_unitprice,product2_stock
product3_name,product3_unitprice,product3_stock
The name of this text file can be taken as an input parameter of your function or you can choose
to use a pre-determined (fixed) name inside of this function. Your function must use exception
handling to handle all possible run-time errors so that this function does not crash.
Please enter your name >> Bond
Hi Bond, please enter your company name >> Mart 007
Let's set up a sales menu for 'Mart 007'.
Enter item 1's name >> Spiked Umbrella
Enter item 1's unit price >> 7.25
Enter item 1's quantity >> 5
Enter item 2's name >> Voice Changer
Enter item 2's unit price >> 5.5
Enter item 2's quantity >> 10
Enter item 3's name >> Spy Camera
Enter item 3's unit price >> fifteen
Price must be a number. Please enter again >> -15
Price must be positive. Please enter again >> 15
Enter item 3's quantity >> eight
Stock must be a number. Please enter again >> -8
Stock must be positive. Please enter again >> 8
And the following will be written to the text file.
Bond,Mart 007
Spiked Umbrella,7.25,5
Voice Changer,5.5,10
Spy Camera,15,8
Step by step
Solved in 4 steps with 4 images