Python Forum
Checking the number of input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking the number of input
#1
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.
Reply
#2
Have you written code that gets the 9 user inputs? Do that first.
Reply
#3
(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()
Reply
#4
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test if an input is any number? wlsa 2 2,339 Oct-03-2018, 04:43 PM
Last Post: wlsa
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 8,831 Apr-20-2018, 04:07 AM
Last Post: pythoneer
  User input only takes the last number Austin11 16 8,050 Nov-28-2017, 11:20 PM
Last Post: Prrz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020