How could I use functions and caling in python to shorten the code of my dice game?

I want to know how to shorten this code using functions and calling python

If ens == "n":
username = entry ("Please enter the appropriate username:")
password1 = entry ("Please enter the password:")
password2 = entry ("Re-enter password:")
if password1 == password2: # checking if both passwords entered are the same
print ("your account was successful, thanks")
file = open ("accountfile.txt", "a")
file.write ("username:")
file.write (username)
file.write ("")
file.write ("password:")
file.write (password2)
file.write (" n")
file.close ()
print ("Please enter & # 39; n & # 39; if you are a new user and & # 39; e & # 39; if you are an existing user")
ens = entry ("")
yes password1! = password2: # if the passwords entered are not the same, they will be repeated until they are entered correctly
correctPassword = (password1)
while True
password = entry (& # 39; Enter password again & # 39;)
If the password == correct password:
Print (& # 39; The correct password has been entered & # 39;)
f = open ("accountfile.txt", "a +")
f.write ("username:")
f.write (username)
f.write ("")
f.write ("password:")
f.write (correctPassword)
f.write (" n")
f.close ()
print ("Please enter & # 39; n & # 39; if you are a new user and & # 39; e & # 39; if you are an existing user")
en = input ("")
print (& # 39; incorrect password & # 39;)

If ens == "e":
counter = 0
check_failed = True
while check_failed:
Print ("Could Player 1 enter his username and password")
username1 = input ("Please enter your username")
password = entry ("Please enter your password")
with open ("accountfile.txt", "r") as username_finder:
for the line in username_finder:
if ("username:" + username1 + "password:" + password) == line.strip ():
print ("you have logged in")
check_failed = False
counter = 0
check_failed = True
while check_failed:
Print ("Could Player 2 enter his username and password")
username2 = input ("Please enter your username")
password = entry ("Please enter your password")
with open ("accountfile.txt", "r") as username_finder:
for the line in username_finder:
if ("username:" + username2 + "password:" + password) == line.strip ():
print ("you have logged in")
check_failed = False
time.sleep (1)
Print ("Welcome to the game of dice")
time.sleep (1)
while rounds < 5:
                                        total_score2 = total_score2 + playerTwoPoints
                                        total_score1 = total_score1 + playerOnePoints
                                        rounds = rounds + 1
                                        number = random.randint(1,6)
                                        number2 = random.randint(1,6)
                                        playerOnePoints = number + number2
                                        print("Round",rounds)
                                        print("-------------------------------------------")
                                        print("Player 1's turn    Type 'roll' to roll the dice")
                                        userOneInput = input(">>> ")
if userOneInput == "roll":
time.sleep (1)
print ("the first roll of player 1 is", number)
print ("second roll of player 1 type & throw" to roll the dice ")
userOneInput = entry (">>>")
if userOneInput == "roll":
time.sleep (1)
print ("the second roll of player 1 is", number 2)
if playerOnePoints% 2 == 0:
playerOnePoints = playerOnePoints + 10
Print ("The total of player 1 is equal to +10 points")
Print("-------------------------------------------")
print ("Player 1 has", playerOnePoints, "points")
plus:
playerOnePoints = playerOnePoints - 5
print ("the total of player 1 is odd so -5 points")
Print("-------------------------------------------")
print ("Player 1 has", playerOnePoints, "points")
number = random.andint (1,6)
number2 = random.andint (1.6)
playerTwoPoints = number + number2
Print("-------------------------------------------")
Print ("Player turn 2 type & roll to roll the dice")
userTwoInput = input (">>>")
if userTwoInput == "roll":
time.sleep (1)
print ("the first roll of player 2 is", number)
print ("second roll of player 2 type & throw" to roll the dice ")
userTwoInput = input (">>>")
if userTwoInput == "roll":
time.sleep (1)
print ("the second throw of player 2 is", number 2)
if playerTwoPoints% 2 == 0:
playerTwoPoints = playerTwoPoints + 10
Print ("The total of Player 2 is still + 10 points")
Print("-------------------------------------------")
print ("Player 2 has", playerTwoPoints, "points")
plus:
playerTwoPoints = playerTwoPoints - 5
print ("the total of player 2 is odd so -5 points")
Print("-------------------------------------------")
print ("Player 2 has", playerTwoPoints, "points")
Print("-------------------------------------------")
print ("The total score for player 1 is", total_score1)
Print("-------------------------------------------")
print ("The total score for player 2 is", total_score2)
Print("-------------------------------------------")
if total_score1> total_score2:
print ("Player 1 wins!")
file = open ("scores.txt", "a")
file.write (username1)
file.write ("has")
file.write (str (total_score1))
file.write ("points")
file.write (" n")
file.close ()
if total_score2> total_score1:
print ("Player 2 wins!")
file = open ("scores.txt", "a")
file.write (username2)
file.write ("has")
file.write (str (total_score2))
file.write ("points")
file.write (" n")
file.close ()
if total_score1 == total_score2:
Print ("It's a tie!")
Print ("So both players will have to roll one more dice")
time.sleep (2)
Print("-------------------------------------------")
Print ("Player's Turn 1 type & roll to roll the dice")
userOneInput = entry (">>>")
if userOneInput == "roll":
time.sleep (1)
print ("the first roll of player 1 is", number)
print ("second roll of player 1 type & throw" to roll the dice ")
userOneInput = entry (">>>")
if userOneInput == "roll":
time.sleep (1)
print ("the second roll of player 1 is", number 2)
if playerOnePoints% 2 == 0:
playerOnePoints = playerOnePoints + 10
Print ("The total of player 1 is equal to +10 points")
Print("-------------------------------------------")
print ("Player 1 has", playerOnePoints, "points")
plus:
playerOnePoints = playerOnePoints - 5
print ("the total of player 1 is odd so -5 points")
Print("-------------------------------------------")
print ("Player 1 has", playerOnePoints, "points")
number = random.andint (1,6)
number2 = random.andint (1.6)
playerTwoPoints = number + number2
Print("-------------------------------------------")
Print ("Player turn 2 type & roll to roll the dice")
userTwoInput = input (">>>")
if userTwoInput == "roll":
time.sleep (1)
print ("the first roll of player 2 is", number)
print ("second roll of player 2 type & throw" to roll the dice ")
userTwoInput = input (">>>")
if userTwoInput == "roll":
time.sleep (1)
print ("the second throw of player 2 is", number 2)
if playerTwoPoints% 2 == 0:
playerTwoPoints = playerTwoPoints + 10
Print ("The total of Player 2 is still + 10 points")
Print("-------------------------------------------")
print ("Player 2 has", playerTwoPoints, "points")
plus:
playerTwoPoints = playerTwoPoints - 5
print ("the total of player 2 is odd so -5 points")
Print("-------------------------------------------")
print ("Player 2 has", playerTwoPoints, "points")
Print("-------------------------------------------")
if total_score1> total_score2:
print ("Player 1 wins!")
file = open ("scores.txt", "a")
file.write (username1)
file.write ("has")
file.write (str (total_score1))
file.write ("points")
file.write (" n")
file.close ()
if total_score2> total_score1:
print ("Player 2 wins!")
file = open ("scores.txt", "a")
file.write (username2)
file.write ("has")
file.write (str (total_score2))
file.write ("points")
file.write (" n")
file.close ()
plus:
print ("Sorry, this username or password does not exist, try again")
counter = counter + 1
if counter == 3:
Print("----------------------------------------------- ----- ")
print ("You have been blocked, restart to try again")
sys.exit ()

plus:
print ("Sorry, this username or password does not exist, try again")
counter = counter + 1
if counter == 3:
Print("----------------------------------------------- ----- ")
print ("You have been blocked, restart to try again")
sys.exit ()

This is part of a project that I have been doing in school. It would be very useful for me if I could rewrite the parts of my code that need improvement or that are wrong step by step so I can understand it better.

Thank you