Python实现相加为奇数则用户赢,如果并且用户能自行选择退出游戏,且计算他们的分数

Consider a game, where both the computer and the user come up with a number. (想出一个游戏,用户和电脑都出一个数字)
a. If both the numbers sum up to an even number, the player wins and the message is displayed. (如果两个数字相加为偶数,则玩家获胜,并且print)
b. The game keeps repeating until the player decides to quit (游戏持续进行,知道玩家决定退出,按q退出游戏)
C. Let's keep a score of who won how many times. Display(print) the score on quit. (计算玩家和电脑分别获胜的次数,并且在按q退出之后显示成绩)

在学python课时候遇到的一个麻烦

import random

users = 0
computers = 0
while True:
    print("Game started")
    computer = random.randint(1, 100)
    user = input("put a number here,hit q to exit")
    if user == "q":
        break
    user = int(user)
    if (computer + user) % 2 == 0:
        users += 1
        print("user win")
    elif (computer + user) % 2 != 0:
        computers += 1
        print("Computer win")
print("user win:",users,"Computer win:",computers)

有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

img

import random
condition=True
while condition:
print("Game started")
word=input("hit q to exit,if not the game will go on")
computer=random.randint(1,100)
user=int(input("put a number here"))

if word=="q":
    condition=False
elif (computer+user)%2==0:
    print("user win")
elif (computer+user)%2!=0:
    print("Computer win")

import random

lis =  ['computer', 'user']
score ={}.fromkeys(lis, 0)

while True:    
    print("Game started")
    computer=random.randint(1,100)
    
    user=input("hit q to exit,if not the game will go on\n")
    if user.isdigit():
        user = int(user)
        print(f"User Number:{user}")    
        print(f"computer number:{computer}")

        if (computer+user)%2==0:
            score['user'] += 1
            print("user win")        
        elif (computer+user)%2!=0:
            score['computer'] += 1
            print("Computer win")        
    elif user == 'q':        
        print(f'User Score:{score["user"]}\nComputer Score:{score["computer"]}')
        break
    else:
        continue