Hey fellow programmers.Im a new python programmer.Only been learning for about 2 weeks.Below is a code I wrote this weekend.It is a simple text adventure.tell me what you think of it.Feel free to copy and paste it into python and run it yourselves.I'm open to suggestions.

#Text adventure v 2.0
print('Hello, please choose a character name.')
charactername=input()

print('Hello' + charactername + ' This is the game of survivial.')
print()
print('You are a noble guard.')
print('The city of Marshingo needs a guard.')
print('Will you be their guard?')
print('Please use lower case letters only.Thank you.')
answer=input()

if answer=='Yes' or answer=='yes':
    print('You have decided to devote yourself to the protection of the city of Marshingo.')
    print('You are currently in the city of Morrige and you need to travel to Marshingo.')
    print('How will you get to Marshingo, by walking or by teleporting?')
    answer=input()
if answer=='walking' or answer=='Walking':
    print('This will be a long and treacherous journey.Prepare yourself with a weapon.')
    print('Would you like to take the sword or the scimitar?')
    answer=input()
if answer=='teleporting':
    print('You teleport yourself into the city of Marshingo with ease.')
    print('You now arrive at Marshingo ready to take your position as guard.')
    print('You report to the guard in charge at the castle and he asks you...')
    print('Would you rather take guard at the entrance to the city or the castle?')
    answer=input()
if answer=='sword' or answer=='Sword':
    print('You arm yourself with the sword and head out on your way.')
    print('You are on your way to Marshingo and a bear jumps out at you!')
    print('What do you do?')
    print('You can run or fight it.Make your choice wisely.')
    answer=input()
if answer=='scimitar' or answer=='Scimitar':
    print('You arm yourself with the scimitar and head out on your way.')
    print('You are on your way to Marshingo and a bear jumps out at you!')
    print('What do you do?')
    print('You can run or fight it.Make your choice wisely.')
    answer=input()

if answer=='run' or answer=='Run':
    print('You escape the bear but in the process you lose your weapon.')
    print('You are now defenseless and have to run to Marshingo.')
    print('You kill the bear valiantly and are on your way now as Marshingo is in sight.')
    print('You now arrive at Marshingo ready to take your position as guard.')
    print('You report to the guard in charge at the castle and he asks you...')
    print('Would you rather take guard at the entrance to the city or the castle?')
    answer=input()
if answer=='fight it' or answer=='Fight it' or answer=='Fight It' or answer=='fight It':
    print('You kill the bear valiantly and are on your way now as Marshingo is in sight.')
    print('You now arrive at Marshingo ready to take your position as guard.')
    print('You report to the guard in charge at the castle and he asks you...')
    print('Would you rather take guard at the entrance to the city or the castle?')
    answer=input()
if answer=='entrance to the city' or answer=='Entrance to the City' or answer=='Entrance to the city':
    print('As you wish, go take up your guard there.')
    print('3 hours after taking up his post, ' + charactername +' notices a rivialing tribe advancing quickly on Marshingo.')
    print('What do you do? ring the alarm or go and talk to them.')
    answer=input()
if answer=='ring the alarm' or answer=='Ring the alarm' or answer=='Ring The Alarm':
    print('You ring the alarm and the entire force of Varrock guards come to defend Varrock.')
    print('The guard in command tells you to prepare for battle.')
    print('You prepare for battle and notice their leader.Do you kill the leader or follow orders?')
    answer=input()
if answer=='kill the leader' or answer=='Kill the leader' or answer=='Kill The Leader':
    print('You kill the leader and the rival tribe''s soldiers get scared away.')
    print('You are the hero of the city to everyone except your fellow soldiers and guard in command.')
    print('You have two options.Accept responsibility for defying orders, or leave the city.')
    answer=input()

if answer=='accept responsibility for defying orders':
    print('You accept responsibility for defying orders and are demoted to the lowest guard position.')
    print('You spend the rest of your days here, at Marshingo.')

if answer=='leave the city':
    print('You leave the city and wander to other cities for the rest of your days.')

if answer=='go and talk to them' or answer=='Go and Talk to them' or answer=='talk to them' or answer=='Talk to Them' or answer=='Talk To Them':
    print('You work up the courage to go and talk to the quickly advancing leader...')
    print('It starts to go peacefully and then BAM! One of their soldiers sneaks up from behind and ends you.')

if answer=='castle' or answer=='Castle':
    print('Okay, as you wish. Take the post by the entrance to the castle.')
    print('After sitting at his post all day ' + charactername + ' notices the king walking around.')
    print('While sitting'+ charactername +' also notices an assasin sneakely following the king.')
    print('You have a very important decision to make. Do you save the king or let him die.')
    answer=input()

if answer=='save the king' or answer=='Save the King' or answer=='Save the king' or answer=='Save The King':
    print('You sneak up on the assasin what do you do?')
    print('End him or knock him out?')
    answer=input()

if answer=='end him' or answer=='End him' or answer=='End Him':
    print('You make the right decision and end him.')
    print('The king graciusly thanks you and carries on his way.')
    print('You then return to your post for the rest of your days.')

if answer=='knock him out' or answer=='Knock him out' or answer=='Knock Him Out':
    print('You knock him out and explain to the king his life was in danger.')
    print('The king graciously thanks you and countinues on his way.')
    print('You then take the assasin to the prison and you return to your post.')

if answer=='let him die' or answer=='Let him die' or answer==' Let Him Die' or answer=='Let him Die':
    print('You hide at your post and pretend you didn''t see anything.')
    print('You think to yourself..well he wasn''t that good of a king anyways.You head the assasin end him below')
    print('You then life the rest of your life guarding the castle and guarding the secret...')
    print('The secret that you let the king die.')

if answer=='no' or answer=='No':
    print('You broke the program due to your laziness to type "yes".')

Recommended Answers

All 4 Replies

Well I guess it is not bad.:)
One small criticism though.
Don't restrict the user in his options. (See line 10)
The same for your if statements, where you test the capitals.
You can avoid all this with the lower() function.
Happy programming.

Thank you. How do you suggest I nrestrict the user in his options? And what do you think a good project would to be work on now. I'm comfortable with if and else statements and sort of with functions. Just want to increase my programming skills.

In the case of upper and lower case that is easy. If your program works best with lowercase input, let the user type what he wants. You, as a programmer, can take care of it behind the scenes converting all the uppercase input into lowercase. The user does not have to know that.
There is this wonderful thread by Vegaseat to continue your explorations: Click Here

Reapting code(answer).
Class or function's is a must to stucture code when it get longer.
This is maybe something you need to learn.

Some tips to get rid of all that if's.
Here use dictionary and convert all input to lowercase(lower())
Then you dont need this 'run' or answer=='Run':
Another option can be to load all that printing info from a file.

game_dict = {
    'walking':
'''This will be a long and treacherous journey.Prepare yourself with a weapon.
Would you like to take the sword or the scimitar?''',
    'teleporting':
'You teleport yourself into the city of Marshingo with ease.',
    'sword':
'You arm yourself with the sword and head out on your way.'
}

answer = input('How will you get to Marshingo, by walking or by teleporting?').lower()
if answer in game_dict:
    print(game_dict[answer])
else:
    print('{} not found in game_dict'.format(answer))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.