简体   繁体   中英

I am trying to figure out how to add a round system of 1-10 on my Rock Paper Python game in my code.

I have this code which is right now complete. One thing i wanted to add is a round system to the game. Where the user chooses between 1-10 rounds and depending oh the choice the game will cycle that many rounds before hitting the play again statement. I tried to use a input() statement but then i ran into the problem of having n int statement when running a while or for loops. Thank you

stored_users = {'jason': 'oeros', 'nicole': 'chance'}
# goes through the funtions in order
def main():

    check_sign_in()

    login()or add_user()

    RockPaperPython()

#asks if you have an account already
def check_sign_in():

    print('Do you want to sign in or create a new user?')

    user_choice = input( 'Create User or Sign In')
    if user_choice == 'Create User':
        add_user()
    if user_choice == 'Sign In':
        login()


# Adds a username and password to the database   
def add_user():
    print('Creating user, \n please create username and password')
    username = input('Username: ')
    password = input('Password: ')
    if stored_users.get(username):
        print('Username already exiss')
        add_user()
    else:
        stored_users[username] = password
        login()

#trails = a counter to see how many tries the user has used to find his info        
trials=0 

# Lets a user sign in, but he has only three attempts
def login():
    global stored_users
    global trials
    print('Please sign in')

    while trials < 3: 
        print('Logging in')
        username = input('Username: ')
        password = input('Password: ')
        if stored_users.get(username) == password:
           print ('Welcome to Rock Paper Python')
           RockPaperPython()
           return True

        else:
            trials += 1
            print ('Wrong username or password')
        if trials >=2 and trials <3 :
            print('if username and password if entered wrong one more time, program will exit')
        if trials >=3:
            exit()

#point system for rock paper python
computer_points=0
user_points=0

#Rock Paper Python the game 
def RockPaperPython():
    print('\nReady to Play Rock Paper Python')




    user_choice = input("\nEnter rock, paper, or python:\n")
    global computer_points
    global user_points
    import random
    my_list = ['rock','paper','python']
    computer_choice = random.choice(my_list)
    print(computer_choice)
    if user_choice == computer_choice:
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('TIE')
    elif user_choice == 'rock' and computer_choice == 'python':
        user_points +=1
        print('User points =', user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    elif user_choice == 'paper' and computer_choice == 'rock':
        user_points +=1
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    elif user_choice == 'python' and computer_choice == 'paper':
        user_points +=1
        print('User points =',user_points)
        print('Computer Points=',computer_points)
        print('WIN')
    else:
        print('You lose :( Computer wins :D')
        computer_points += 1
        print('User points =',user_points)
        print('Computer Points=',computer_points)


        Play_Again= input('Play Again? Yes or NO')
    if Play_Again == 'Yes':
        RockPaperPython()

    else:
        print('Thanks for Playing')
        main()

main()
stored_users = {'jason': 'oreos', 'nicole': 'chance'}
# goes through the funtions in order
def main():

    check_sign_in()

    login()or add_user()

    RockPaperPython()

#asks if you have an account already
def check_sign_in():

    print('Do you want to sign in or create a new user?')

    user_choice = raw_input( 'Create User or Sign In? ')
    if user_choice == 'Create User':
        add_user()
    if user_choice == 'Sign In':
        login()


# Adds a username and password to the database   
def add_user():
    print('Creating user, \n please create username and password')
    username = input('Username: ')
    password = input('Password: ')
    if stored_users.get(username):
        print('Username already exist')
        add_user()
    else:
        stored_users[username] = password
        login()

#trails = a counter to see how many tries the user has used to find his info        
trials=0 

# Lets a user sign in, but he has only three attempts
def login():
    global stored_users
    global trials
    print('Please sign in')

    while trials < 3: 
        print('Logging in')
        username = raw_input('Username: ')
        password = raw_input('Password: ')
        if stored_users.get(username) == password:
           print ('Welcome to Rock Paper Python')
           RockPaperPython()
           return True

        else:
            trials += 1
            print ('Wrong username or password')
        if trials >=2 and trials <3 :
            print('if username and password if entered wrong one more time, program will exit')
        if trials >=3:
            exit()

#point system for rock paper python
computer_points=0
user_points=0

#Rock Paper Python the game 
def RockPaperPython():
    print('\nReady to Play Rock Paper Python')


    cycles = int(raw_input("Enter how many rounds you want to play: "))
    for i in range(1, cycles):
        user_choice = raw_input("\nEnter rock, paper, or python:\n")
        global computer_points
        global user_points
        import random
        my_list = ['rock','paper','python']
        computer_choice = random.choice(my_list)
        print(computer_choice)
        if user_choice == computer_choice:
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('TIE')
        elif user_choice == 'rock' and computer_choice == 'python':
            user_points +=1
            print('User points =', user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        elif user_choice == 'paper' and computer_choice == 'rock':
            user_points +=1
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        elif user_choice == 'python' and computer_choice == 'paper':
            user_points +=1
            print('User points =',user_points)
            print('Computer Points=',computer_points)
            print('WIN')
        else:
            print('You lose :( Computer wins :D')
            computer_points += 1
            print('User points =',user_points)
            print('Computer Points=',computer_points)

    Play_Again= input('Play Again? Yes or NO')
    if Play_Again == 'Yes':
        RockPaperPython()

    else:
        print('Thanks for Playing')
        main()

main()

There ya go I changed the input() to raw_input() in some parts and fixed some spelling mistakes. See if it works for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM