0

I tried to do upper() and lower() and even changing the Y and N's to lowercase inside the code. It works if I put in uppercase Y and N but I keep getting errors if I type in lowercase y or n. Anyone know a solution?

def patternSum(myDice):
    if allSame(myDice):
       patternPoints=input("\nWould you like to score the pattern points for all different values (25 points)? [Y/N]: ")
       patternPoints.lower()
       if patternPoints == "Y":
          points = 25
          sumDice=input("Would you like to score the sum of the dice (16 points)? [Y/N]: ")
          if sumDice == "Y":
             points = 25 + 16
          if sumDice == "Y":
             points = 16
       elif patternPoints == "N":
          sumDice=input("Would you like to score the sum of the dice (16 points)? [Y/N]: ")
          points = 16
       else:
          print("Please try again by entering Y or N.")
    else:
        points = sum(myDice)
        print( "Your score is now:",patternSum([1,1,1,1,1]),".\n" )

    return points
score = score + patternSum(myDice)
Ben
  • 29
  • 7
  • First of all, doing patternPoints.lower() will not convert patternPoitns to lower case string. You actually have to put it into a variable. Secondly, I don't know what you're doing with "if allSame(myDice):". Are you just trying to put the concept ? Because I'm not sure if that's a correct syntax of writing if block in Python. – Plabon Dutta Nov 28 '19 at 19:59
  • I think you should consider putting `patternPoints.lower()` to a variable first. Because `lower()` and `upper()` does not mutate the original string. – Plabon Dutta Nov 28 '19 at 20:34

2 Answers2

2

You are not updating the value to the variable patternPoints.

patternPoints.lower() doesn't change the value of patternPoints.

You should have done patternPoints = patternPoints.upper() on 4th line.

Underoos
  • 3,105
  • 3
  • 22
  • 47
1

In the code you posted, you put lower() and compare to a upper case input, but, the lower() and upper() functions return the transformed string, it does not alter the current string.

I've changed your code to:

def patternSum(myDice):
    if allSame(myDice):
       patternPoints=input("\nWould you like to score the pattern points for all different values (25 points)? [Y/N]: ")
       if patternPoints.lower() == "y":
          points = 25
          sumDice=input("Would you like to score the sum of the dice (16 points)? [Y/N]: ")
          if sumDice.upper() == "Y":
             points = 25 + 16
          if sumDice == "Y":
             points = 16
       elif patternPoints.upper() == "n":
          sumDice=input("Would you like to score the sum of the dice (16 points)? [Y/N]: ")
          points = 16
       else:
          print("Please try again by entering Y or N.")
    else:
        points = sum(myDice)
        print( "Your score is now:",patternSum([1,1,1,1,1]),".\n" )

    return points
score = score + patternSum(myDice)