79607551

Date: 2025-05-05 19:56:14
Score: 1
Natty:
Report link

I've discovered the problem and a solution.

In the original code, I was converting a float into a string and wanted to print out a statement if the last character of the string was a certain number:

    elif operationChoice == 6:
        if choice1 < 0:
            print(f"Evaluating the nth root of a negative number is not supported by this calculator.")
            print(f"Try again!")
            continue
        result = mathDict[6](choice1, choice2)
        if str(choice2)[-1] == "2":
            print(f"The {choice2}nd root of {choice1} equals {result}")

The problem is that the last character of a float will be AFTER the decimal point and not before.

This code appears to fix my problem and prints the output I want.

elif operationChoice == 6:
    if choice1 < 0:
        print(f"Evaluating the nth root of a negative number is not supported by this calculator.")
        print(f"Try again!")
        continue
    result = mathDict[6](choice1,int(choice2))
    placeholderValue = result
    if str(choice2)[-3] == "2":
        print(f"The {str(choice2)[0:-2]}nd root of {choice1} equals {result}")

The output for an input of 25 for choice1 and 2 for choice2 is:
The 2nd root of 25.0 equals 5.0

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: John-Michael-D