Уведомления

Группа в Telegram: @pythonsu

#1 Дек. 10, 2021 20:07:52

esliceyament
Зарегистрирован: 2021-12-10
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Помогите изменить код

Всем привет! Я во всей этой теме новый и у меня возникла проблема с кодом. Написал я игру камень, ножницы, бумага на пайтон, вроде все работает нормально, но возникает проблема со счетом - он начинает считать заново, я понимаю почему, но голову сломал над этим счетом. Прошу, если кто знает, как изменить код так, чтобы он работал корректно, исправить! Заранее огромное спасибо!!

Прикреплённый файлы:
attachment 123.txt (2,2 KБ)

Офлайн

#2 Дек. 11, 2021 03:41:48

py.user.next
От:
Зарегистрирован: 2010-04-29
Сообщения: 9897
Репутация: +  855  -
Профиль   Отправить e-mail  

Помогите изменить код

  
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()



Офлайн

#3 Дек. 11, 2021 21:50:47

xam1816
Зарегистрирован: 2020-05-11
Сообщения: 1372
Репутация: +  122  -
Профиль   Отправить e-mail  

Помогите изменить код

 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))

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version