我有这个代码,现在是完整的。我想在游戏中加入一个回合制。如果用户在1-10轮之间进行选择,根据选择,游戏将循环许多轮,然后再次点击play语句。
我尝试使用input()
语句,但在运行while
或for
循环时遇到了使用n int
语句的问题。
谢谢
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()
好了,我在某些部分把input()改成了raw\u input(),纠正了一些拼写错误。看看对你有用吗
相关问题 更多 >
编程相关推荐