Python Rock-paper-scissors question

Asked 2 years ago, Updated 2 years ago, 15 views

import random win=0 draw=0 lose=0

while 1: com=random.randint(0,2) print ('Computer:',com) a=int('0:Scissors 1: Rock 2: Paper:') res=com-a

if res==0:
    print('draw \n')
if res==-1 or res==2:
    print('win \n')
    win=win+1
if res==1 or res==-2:
    print('lose \n')
    lose=lose+1

The moves are good up to here If you type 9, you'll be able to see how many wins, losses, and winning percentages you'll get I have to finish it, but it's not working. What should I do?

python

2022-09-22 18:38

1 Answers

Just in time, I made a rock-paper-scissors demo with JS because of the old questionnaire, and it's a good thing that I realized the winning rate. Just to show you a little bit:

var totalGames = 0
var wonGames = 0
// I'm going to...

.on(when you input something, function() {
    If (unless input is 9) {
        totalGames++
        // I'm going to...

        If (when winning) {
            wonGames++
        }
        // I'm going to...

    } } else {
        // If 9 is input as soon as it starts and terminates, a division error may occur.
        if (totalGames == 0) {
            totalGames = 1
            wonGames = 0
        }
        alert('My winning rate:' + (wonGames * 100 / totalGames) + '%')
        // The following is omitted...
    }
})


2022-09-22 18:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.