Python Forum
Homework (counting iteration issue)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework (counting iteration issue)
#1
Below is my Homework assignment. I cannot for the life of me figure out why my while loop
doesn't recognize my condition != 'no'. The loop will not exit when 'no' is entered. ANY insight would be great!

# This program will ask a user to input the length of
# three sides to a triangle.When the user inputs the
# side lengths the program will determine whether
# the triangle is Isosceles, Equilateral, Not equilateral or isosceles.
# The program will then give the total number of triangles processed.

def main():
    # Initialize counter
    answer = 0
    # Get the user to answer yes or no.
    userAnswer = str(input("Would you like to enter three sides to a" + \
                           "triangle? Please answer yes or no:"))
    # Gather side data
    side1 = int(input("Side 1 Size?"))
    side2 = int(input("Side 2 Size?"))
    side3 = int(input("Side 3 Size?"))
    # Calculate side data
    while userAnswer != 'no':
        answer += 1
        if side1 == side2 == side3:
            print("Equilateral triangle")
            break
        elif side1 != side2 != side3:
            print("Not equilateral or isosceles")
            break
        else:
            print("Isosceles triangle")
            break
    print("Processing is complete. You have evaluated", answer, "sets of sides.")
    main()
    print("Processing is complete. You have evaluated", answer, "sets of sides.")


main()
Reply


Messages In This Thread
Homework (counting iteration issue) - by Cardinal07 - Feb-25-2018, 05:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  saving issue on homework assignment russoj5 2 2,012 Oct-26-2020, 01:53 PM
Last Post: russoj5
  Need help with iteration homework Dendro 2 2,459 Oct-18-2018, 02:53 AM
Last Post: stullis
  Issue with logic in homework fad3r 5 3,724 May-24-2018, 08:13 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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