Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
print('This is created by Hamza Ayub')
lose = 'The couputer won'
win = 'You won!!'
lives = 3
score = 0
draw = 0
comp_lives = 5
while True :
    print('fill in the information below :')

    username = input('Enter your username :  ')

    password = input('Enter your password :  ')

    searchFile = open('D:\RPS GAME\ accounts(1).xlsx', 'r')

    for line in searchFile: # this will look for a line in the document
        if username and password in line :
            print ('Access granted')
            print('RULES!!!!!')
            print('---------------------------------')
            print('you will have ' + str(lives) + ' lives and the computer will have 5')
            print('---------------------------------')
            print('You lose a live if you lose, but, fain one if you win, it is the same with the computer')
            print('---------------------------------')
            print('Choose either rock, paper or scissors')
            print('---------------------------------')
            print('type lives to see livs; score to see score; and draw to see draws')
            print('---------------------------------')
            print('GOOD LUCK!!!!!!!!!')
            print('---------------------------------')

            while True :
                rps = input('Choose your weapon. Rock, paper or scissors?  ')
                import random 
                computer = ('rock', 'paper', 'scissors')
                computer = random.choice(computer)
                # rock if statment:
                if rps == 'rock' or 'Rock' and computer == 'paper' :
                    print('The computer chose ' + computer )
                    print('')
                    print(lose)
                    print('')
                    lives - 1 

                if rps == 'rock' or 'Rock' and computer == 'scissors' :
                     print('The computer chose ' + computer )
                     print('')
                     print(win)
                     print('')
                     score += 1 

                # scissors if statment
                if rps == 'scissors' or 'Scissors' and computer == 'paper' :
                     print('The computer chose ' + computer )
                     print('')
                     print(win)
                     print('')
                     score += 1 
                
                if rps == 'scissors' or 'Scissors' and computer == 'rock' :
                    print('The computer chose ' + computer )
                    print('')
                    print(lose)
                    print('')
                    lives - 1
                # paper if ststment
                
                if rps == 'paper' or 'Paper' and computer == 'rock' :
                    print('The computer chose ' + computer )
                    print('')
                    print(win)
                    print('')
                    score += 1

                if rps == 'paper' or 'Paper' and computer == 'scissors' :
                    print('The computer chose ' + computer )
                    print('')
                    print(lose)
                    print('')
                    lives - 1 

                # rock draw
                if rps == 'rock' or 'Rock' and computer == 'rock' :

                    print('The computer chose ' + computer )
                    print('')
                    print('its a draw')
                    print('')
                    draw += 1

                # scissor draw 
                if rps == 'scissors' or 'Scissors' and computer == 'scissors' :

                    print('The computer chose ' + computer )
                    print('')
                    print('its a draw')
                    print('')
                    draw += 1

                # paper draw
                if rps == 'paper' or 'Paper' and computer == 'paper' :

                    print('The computer chose ' + computer )
                    print('')
                    print('its a draw')
                    print('')
                    draw += 1

                if rps == 'lives' or 'Lives' :
                    print(lives)
                
                if rps == 'score' or 'Score' :
                    print(score)

                if rps == 'draw' or 'Draw' :
                    print(draw)

                if lives == 0 or rps == 'test' :
                    print('you ran out of lives :(')
                    print('Your score is ' + score)
                    print('you drew ' + draw + ' times')
                    stop = input('Press enter to exit')
                    import time 
                    time.sleep(900)

                if comp_lives == 0 :
                    print('You won, the computer ran out of lives !!!!! :)')
                    print('Your score is ' + score)
                    print('you drew ' + draw + ' times')
                    stop = input('Press enter to exit')
                    import time 
                    time.sleep(900)
                
                if rps == 'exit' or 'Exit' :
                    break
                else :
                    print('Your password or username is incorrect')


this is my code but what it shows is :

<pre>This is created by Hamza Ayub
fill in the information below :
Enter your username :  hmz     
Enter your password :  123
Access granted
RULES!!!!!
---------------------------------
you will have 3 lives and the computer will have 5
---------------------------------
You lose a live if you lose, but, fain one if you win, it is the same with the computer
---------------------------------
Choose either rock, paper or scissors
---------------------------------
type lives to see livs; score to see score; and draw to see draws    
---------------------------------
GOOD LUCK!!!!!!!!!
---------------------------------
Choose your weapon. Rock, paper or scissors?  paper
The computer chose paper

The couputer won        

The computer chose paper

You won!!

The computer chose paper

You won!!

The computer chose paper

The couputer won

The computer chose paper

its a draw

3
2
1
fill in the information below :
Enter your username :


what its supposed to do is that when I type either one object and according to the computer's pick it use the if statement, but it just prints everything

What I have tried:

i tried to look for it online, but, nothing helped
Posted
Updated 14-Jun-23 3:50am
Comments
Richard MacCutchan 14-Jun-23 11:19am    
The follopwing statement (repeated a number of times) is wrong:
                    lives - 1


That just evaluates the sum, but does not store it anywhere. See my updated answer for how you can get rid of all the duplicated code.

Here is a similar question, with suggestions for improvement: I was making a simple stone paper scissor game and the if else is not exexuting[^]. Google will find you many more samples.

[edit]
Here is the basic logic of the fgame, without the extra checks for the number of lives:
Python
def rps_game():
    choices = ['rock', 'paper', 'scissors']
    computer = random.choice([0,1,2])

    user = int(input("Select your weapon:\n\t1 - Rock\n\t2 - Paper\n\t3 - Scissors\n\t: ")) - 1

    print(F'the computer chose {choices[computer]}')
    print(F'         you chose {choices[user]}')

    match computer:
        case 0: # rock
            win = user == 1
            lose = user == 2
        case 1: # paper
            win = user == 2
            lose = user == 0
        case 2: # scissors
            win = user == 0
            lose = user == 1

    if win:
        print("Congratulations, you win")
    elif lose:
        print("Hard cheese, you lost")
    else:
        print("Wow, it's a draw")

This eliminates all your duplicate code, and the problems that may be caused by the user not using the correct spelling or character casing.

[/edit]
 
Share this answer
 
v3
Comments
OriginalGriff 14-Jun-23 9:39am    
Did you forget the link?
Richard MacCutchan 14-Jun-23 9:40am    
Oops, thank you, fixed now.
It's down to how you write your if condition:
Python
if rps == 'rock' or 'Rock' and computer == 'rock' :
'Rock' is a string on it's own and since it's not empty, it is treated as TrueYou need to add the comparison explicitly:
Python
if rps == 'rock' or rps=='Rock' and computer == 'rock' :
Or better:
Python
if (rps == 'rock' or rps=='Rock') and computer == 'rock' :
To get it working - the brackets force a particular evaluation order on the conditions, so rps must be one or other of "rock" and "Rock" and the computer needs to be "rock" as well.

The language is different, but he made the same mistakes you have - so have a look at his question, and my response: I was making a simple stone paper scissor game and the if else is not exexuting[^] - the advice is the same as for you!
 
Share this answer
 
Comments
Hamza Ayub 14-Jun-23 10:28am    
well thanks, liked the way you explained it
OriginalGriff 14-Jun-23 11:16am    
You're welcome!
Andre Oosthuizen 14-Jun-23 10:29am    
Another 1 vote... :( my +5
Hamza Ayub 14-Jun-23 10:44am    
y the sad face?
OriginalGriff 14-Jun-23 11:18am    
Somebody is down voting everything I do - it doesn't matter at all, I don't really pay attention to my rep. I think I annoyed him when I explained why we don't do homework for people! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900