I'm asking you a question while making Python baseball game

Asked 2 years ago, Updated 2 years ago, 79 views

import random
random_ball = random.sample((1,2,3,4,5,6,7,8,9),3)

strike = 0
ball = 0

while True:
    Guess = input ("Please enter three different baseball numbers (1 to 9): ")
    if random_ball == guess:
        print ("Correct")
        break

    for i in guess:
        if i == random_ball:
            if guess.index(i) == random_ball.index(i):
                strike += 1
            else:
                ball += 1
        else:
            pass
print("strike:{}, ball:{}".format(strike, ball))

python baseball-game

2022-09-20 08:40

1 Answers

Here! Cheer up a little more.


2022-09-20 08:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.