[英]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.
用户在1-10个回合之间进行选择,然后根据选择进行选择,游戏将循环多次回合,然后再次按下播放语句。 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. 我试图使用
input()
语句,但是随后在运行while
或for
循环时遇到了n个int
语句的问题。 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. 在某些地方,我将input()更改为raw_input()并修复了一些拼写错误。 See if it works for you
看看是否适合您
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.