Найти - Пользователи
Полная версия: Помогите изменить код
Начало » Python для новичков » Помогите изменить код
1
esliceyament
Всем привет! Я во всей этой теме новый и у меня возникла проблема с кодом. Написал я игру камень, ножницы, бумага на пайтон, вроде все работает нормально, но возникает проблема со счетом - он начинает считать заново, я понимаю почему, но голову сломал над этим счетом. Прошу, если кто знает, как изменить код так, чтобы он работал корректно, исправить! Заранее огромное спасибо!!
py.user.next
  
import random
 
def main(score):
        textForUser()
        randomNumber()
        random_number = randomNumber()
        user_number = userNumber()
        computer_score = computerScore(score[0])
        user_score = userScore(score[1])
        conditionForComputer(random_number)
        new_score = conditionForUser(
                random_number,
                user_number,
                computer_score,
                user_score)
        return new_score
 
def computerScore(computer=0):
        return computer
 
def userScore(user=0):
        return user
 
def textForUser():
        print('1 - Rock, 2 - Paper, 3 - Scissors')
 
def randomNumber():
        random_number = random.randint(1, 3)
        return random_number
 
def userNumber():
        user_number = int(input('--> '))
        return user_number
 
def conditionForComputer(random_number):
        if random_number == 1:
                print('Computer chose rock')
        elif random_number ==2:
                print('Computer chose paper')
        elif random_number ==3:
                print('Computer chose scissors')
 
def conditionForUser(num1, num2, num3, num4):
        if num1 == 1 and num2 == 2:
                num4 += 1
                print('You win', num3, ' : ', num4)
        elif num1 == 1 and num2 == 3:
                num3 += 1
                print('You lose', num3, ' : ', num4)
        elif num1 == 2 and num2 == 1:
                num3 += 1
                print('You lost', num3, ' : ', num4)
        elif num1 == 2 and num2 == 3:
                num4 += 1
                print('You win', num3, ' : ', num4)
        elif num1 == 3 and num2 == 1:
                num4 += 1
                print('You win', num3, ' : ', num4)
        elif num1 == 3 and num2 == 2:
                num3 += 1
                print('You lost', num3, ' : ', num4)
        elif num1 == num2:
                num3 += 1
                num4 += 1
                print('It is draw', num3, ' : ', num4)
        return num3, num4
 
def loopForGame():
        y = 'y'
        score = (0, 0)
        while y == 'y' or y == 'Y':
                score = main(score)
                y = input('Continue? Y or y for yes: ')
 
loopForGame()
xam1816
 import random
items = {1: 'КАМЕНЬ', 2: 'НОЖНИЦЫ', 3: 'БУМАГА'}
count_player = 0
count_comp = 0
f = lambda i: (i) % 3 + 1
while player_choice := input('1) => камень 2) => ножницы 3) => бумага\n>>>'):
    if player_choice in ['1', '2', '3']:
        player_choice = int(player_choice)
        comp_choice = random.choice((1, 2, 3))
        if player_choice != comp_choice:
            if f(player_choice) == comp_choice:
                count_player += 1
            else:
                count_comp += 1
        print(f'\nВы: {items[player_choice]} <VS> компьютер: {items[comp_choice]}')
        print('{:>15}\n'.format('очки'))
        print('{:< 10}:{:>10}\n'.format(count_player, count_comp))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB