Checking the number of input - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Checking the number of input (/thread-36644.html) |
Checking the number of input - Chrilo06 - Mar-13-2022 Hi, I have this homework that I am currently having trouble at. How can I check multiple input of a user if everything is equal? and if it is not equal there should be an error message to be printed out. Here is the instruction: "However, if the user entered any number of arguments, other than overall 9 (the edges and the height) - then, the error "Error!" should be printed instead. Also note all 8 base edges should be equal with each other, and, not be equal to zero or a negative number, otherwise, the error should be printed." any enlightenment and code samples for this area would be so much appreciated and would help me further into my journey. RE: Checking the number of input - deanhystad - Mar-13-2022 Have you written code that gets the 9 user inputs? Do that first. RE: Checking the number of input - Chrilo06 - Mar-14-2022 (Mar-13-2022, 05:35 PM)deanhystad Wrote: Have you written code that gets the 9 user inputs? Do that first.here is the input: inp = input().split() height = float(inp[0]) edges = (float(inp[x]) for x in range(1,len(inp))) o = OctPrism(height,*edges) o.printResults() RE: Checking the number of input - deanhystad - Mar-14-2022 Verify that len(edges) == 8. If not, raise an exception or print a message that says "Error". You should also provide the user with some guidelines on what to enter. Maybe have two inputs; height and edges. height = float(input("Enter the height: ") edges = map(float, input("Enter length of the 8 sides separated by spaces: ").split())I think it odd that the user needs to enter eight edge values and is forced to enter the same value for each. But this is homework and a lot of homework assignments make no sense. Any ideas on how you are going to verify that all edges are the same? |