I need help simplifying this Python code. I'm new, this adventure game is one of my first projects. I have tried simplifying my code already and this was the best result I could get.
import time
import random
r = random.randrange(10)
#r is the weapon being used for gun
#pauses the story
def print_pause(lines):
for line, pause in lines:
print(line)
time.sleep(pause)
def print_sep():
print("You chose " + answer + ".")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
def game_over():
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("""
___
/ __|__ _ _ __ ___ _____ _____ _ _
| (_ / _` | ' \/ -_) / _ \ V / -_) '_|
\___\__,_|_|_|_\___| \___/\_/\___|_|
""")
def win():
print("""
_ _ _
| | | | (_)
| |___| | ___ _ _ _ _ _ _ ____
|_____ |/ _ \| | | | | | | | | _ \
_____| | |_| | |_| | | | | | | | | |
(_______|\___/|____/ \___/|_|_| |_|
""")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("Soviet Union, 1988")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
time.sleep(1)
name = input("Comrade, what is your name?")
print_pause([
("-- KGB Offices, Moscow --", 1),
("Glory to the party and the glorious leader, " + name + ".", 2),
("You were arrested after participating in a democratic protest in\nKazan yesterday. My name is Vladimir; tell me what happened.", 3),
("Do you: \n A: Tell the KGB officer everything \n B: Say nothing", 0) #how many seconds to rest
])
answer = input("A or B?")
print_sep()
if answer == "A":
print_pause([
("You tell Vladimir everything; and he approaches you with a\nlucrative offer.", 3),
("You have a one time opportunity to join the KGB, otherwise you face prison time.", 3),
("Do you: \n A: Accept the offer \n B: Decline the offer", 3)
])
answer = input("A or B?")
print_sep()
if answer == "A":
print_pause([
("Agent " + name + ", welcome to the KGB.", 1),
("Here is your badge and gun; your first task; help us arrest known\ndissident guards at the Inner German border.", 3),
("You are sent to the Inner German border; and soon you are feet away from West Germany. Do you escape?", 3),
("Do you: \n A: Escape \n B: Continue on your mission", 3)
])
answer = input("A or B?")
print_sep()
if answer == "A":
if r > 5:
print_pause([
("Success, you escaped from the Eastern Bloc.", 2),
("Wait another 3 years, and all of communism collapses.", 2)
])
win()
else:
print_pause([
("As you try to climb across the border, you step on an infamous\nSM-70 mine.", 3),
("80 steel cubes rip into your body.", 2)
])
game_over()
elif answer == "B":
print_pause([
("You find the guard dissident, and you shout 'HALT!'", 2),
("He whips around, but before he can shoot you, you tackle him to the ground", 3),
("For the rest of your life, you continue to work for the KGB, and retire comfortably after the collapse of the USSR", 3)
])
win()
elif answer == "B":
print_pause([
("Prison, like Vladimir said, is your new home.", 2),
("But the USSR collapses in 1991; so you are free to go after 3 years!", 3),
("Unfortunately the KGB wants you to keep quiet about what you went\nthrough so a splinter faction kills you to make sure you don't leak\nany info.", 3)
])
game_over()
elif answer == "B":
print_pause([
("You are tortured for days on by Vladimir.", 2),
("Just when you think you lost all hope, you find an opportunity: his pistol left on the table.", 2),
("Do you:\n A: Grab the pistol \n B: Leave it on the table", 2.5)
])
answer = input("A or B?")
print_sep()
if answer == "A":
if r > 5:
print_pause([
("You pick up the pistol. It's a Makarov; standard issue for KGB. You fire!\nThe bullet whizzes through the air... and hits it's mark!", 3),
("Vladimir lies in a pool of blood as you run." , 2),
("Do you: \n A: Run away \n B: Surrender", 2)
])
answer = input("A or B?")
print_sep()
if answer == "A":
print_pause([
("You escape... barely.", 2),
("You spend the rest of your years in hiding until your charges are dropped after the dissolution of the USSR.", 3)
])
win()
elif answer == "B":
print_pause([
("Bad choice... the USSR carries the death penalty for murder cases.", 2)
("I'll leave the rest to your imagination.", 2)
])
game_over()
else:
print_pause([
("You shoot, and the bullet whizzes past Vladimir, hitting the wall.", 3),
("He easily whips around and chokes you to death with the ferocity of a bear." , 2)
])
game_over()
elif answer == "B":
print_pause([
("You tried your best, but eventually you gave up.", 2),
("You told Vladimir everything, and a show trial exiles you to a gulag.", 2),
("The rest of your days you spend working in the Siberian cold.", 2)
])
game_over()