New to python and having problems with whiles and ifs

My Problem(s): The problem now is that whenever I enter a number of times to play, it just ignores it and plays forever. It is also not updating the score even though I have global variables and I am adding to them every time there is a win or loss.

My Program Also, I do not want to ask the player(s) for their names every time they play (only when using the “out of a certain number of points function of the game). Any suggestions/help would be greatly appreciated!

My code is below for reference:

from random import randint
import sys

print("Lets play a game!")
dotheywantotplay = input("Do you want to play Rock-Paper-Scissors? (y or n) ")
bestOutOf = int(input("Best out of: (Enter a number 1-10) "))

player1score = 0
player2score = 0
computerscore = 0

class PlayWithFriend:
    def __init__(self, player1, player2, name1, name2, player1score, player2score):

        self.player1 = player1
        self.player2 = player2
        self.name1 = name1
        self.name2 = name2
        self.player1score = player1score
        self.player2score = player2score

        if player1 == player2:
                print("Tie!")
        elif player1 == "Rock":
            if player2 == "Paper":
                print("You Win", name2,"!")
                print(player2, "covers", player1)
                player2score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
            else:
                print("You Win", name1,"!")
                print(player1, "smashes", player2)
                player1score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
        elif player1 == "Paper":
            if player2 == "Scissors":
                print("You Win", name2,"!")
                print(player2, "cut", player1)
                player2score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
            else:
                print("You Win", name1,"!")
                print(player1, "covers", player2)
                player1score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
        elif player1 == "Scissors":
            if player2 == "Rock":
                print("You Win", name2,"!")
                print(player2, "smashes", player1)
                player2score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
            else:
                print("You Win", name1,"!")
                print(player1, "cut", player2)
                player1score += 1
                print("The score is -->  %d: %s vs %d: %s" %(player1score, name1, player2score, name2))
        else:
            print("That's not a valid play. Check your spelling!")

class PlayWithComputer:
    def __init__(self, player, name, player1score, computerscore):

        self.player = player
        self.player1score = player1score
        self.computerscore = computerscore
        self.name = name

        t = ["Rock", "Paper", "Scissors"]

        computer = t[randint(0,2)]

        if player == computer:
            print("Tie!")
            print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
        elif player == "Rock":
            if computer == "Paper":
                print("You lose!", computer, "covers", player)
                computerscore += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
            else:
                print("You win!", player, "smashes", computer)
                player1score += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
        elif player == "Paper":
            if computer == "Scissors":
                print("You lose!", computer, "cut", player)
                computerscore += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
            else:
                print("You win!", player, "covers", computer)
                player1score += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
        elif player == "Scissors":
            if computer == "Rock":
                print("You lose...", computer, "smashes", player)
                computerscore += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
            else:
                print("You win!", player, "cut", computer)
                player1score += 1
                print("The score is -->  %d: %s vs %d: computer" %(player1score, name, player2score))
        else:
            print("That's not a valid play. Check your spelling!")

if dotheywantotplay == "y":

    PlayWith = input("Do you want to play Rock-Paper-Scissors with computer or a friend? (computer, friend, exit) ")

    while  PlayWith in ('computer', 'friend', 'exit'):

        if PlayWith == "friend":

            player1 = input('Enter first players name: ')
            player2 = input('Enter second players name: ')
            while player1score + player2score < bestOutOf:

                personchoice1 = input("First player... Rock, Paper or Scissors?  ")
                personchoice2 = input("Second player... Rock, Paper or Scissors?  ")
                PlayWithFriend(personchoice1, personchoice2, player1, player2, player1score, player2score)
        elif PlayWith == "computer":

            player = input('Enter first players name: ')
            while player1score + computerscore < bestOutOf:

                personchoice = input("Rock, Paper, Scissors?  ")
                PlayWithComputer(personchoice, player,  player1score, computerscore)
        elif PlayWith == "exit":
            sys.exit()

        else:
            print("That's not a valid play. Check your spelling!")
else:
    print("I am sad now :-(")
    sys.exit()

Answer

I went over your code and cleaned it up. I made the formatting, variable names, and processes much more pythonic. You will find it is much easier to use python when you use these best practices, so I recommend you at least look over the code and see what I did. For me, I know this would’ve been helpful when I started learning python.

from random import choice


def get_result(choice1, choice2):
    return {
        ('paper', 'rock'): dict(win='player 1', action='covers'),
        ('rock', 'paper'): dict(win='player 2', action='covers'),
        ('rock', 'scissors'): dict(win='player 1', action='smashes'),
        ('scissors', 'rock'): dict(win='player 2', action='smashes'),
        ('scissors', 'paper'): dict(win='player 1', action='cuts'),
        ('paper', 'scissors'): dict(win='player 2', action='cuts'),
    }[(choice1, choice2)]  # index this dictionary


def main():
    print('Lets play a game!')
    if input('Do you want to play Rock-Paper-Scissors? (y or n) ') != 'y':
        quit()
    num_games = int(input('Best out of: (Enter a number 1-10) '))
    num_games = max(min(num_games, 10), 1)  # clamp num_games between 1-10
    while True:  # infinite loop, we can break out or quit when we need
        inp = input('Do you want to play Rock-Paper-Scissors with computer or a friend? (computer, friend, exit) ')
        if inp == 'exit':
            quit()
        play_with_computer = inp == 'computer'

        name1 = input('Enter first players name: ')
        name2 = 'computer' if play_with_computer else input('Enter second players name: ')

        score = {name1: 0, name2: 0}
        for game_number in range(num_games):
            choice1 = input(f'{name1}... rock, paper or scissors? ')
            choice2 = choice(['rock', 'paper', 'scissors']) if play_with_computer else input(f'{name2}... rock, paper or scissors? ')
            if choice1 == choice2:
                print('Tie!')
                continue
            result = get_result(choice1, choice2)
            win_name = name1 if result['win'] == 'player 1' else name2
            lose_name = name2 if result['win'] == 'player 1' else name1
            score[win_name] += 1
            print(f'{win_name} {result["action"]} {lose_name}')
            print(f'Game {game_number+1}, the score is {score[name1]} {name1}, {score[name2]} {name2}')
        print(name1 if score[name1] > score[name2] else name2, 'wins!')


if __name__ == '__main__':  # this just means if the file is run
    main()

The main thing I did was get rid of your rock paper scissors logic, (which you repeated twice which is never best practice in programming), and replaced it with a get_result function which returns the winner and action of the moves. I also replaced your if statements that test if the game is against the computer, with a bool play_with_computer. This can be used when getting player 2 name and the second choice, which is all that is really different when playing with a computer. The last thing is your game loop while. Since you never really need to execute any code after this (only reason to exit is to quit), I find it to be cleaner to have an infinite loop while True, and just call quit() if the input is 'exit'.