Dragon Realm Part 1 & 2
Recently in my
twenty percent project, I have reached chapter six in invent with python. This chapter
talks about the first game. Part 1 talks about the basis of the code and how
complex it is to make and you must learn several things, to remind you of what
you use and when you use it. In this circumstances the def block is one of the
important ones, where you learn about the global scope and the local scope. In part 2, essential piece of information is that you can put code inside the parentheses,
this is called a parameter. By using the parameters, we can use it to call old
functions. In the recent project, we were creating our own functions and
calling them by parentheses, by making your own functions coding is easier and
more simple.
The Code I used:import random
import time
def displayIntro():
print('You are in a land full of dragons. In front of you,')
print('you see two caves. In one cave, the dragon is friendly')
print('and will share his treasure with you. The other dragon')
print('is greedy and hungry, and will eat you on sight.')
print()
def
chooseCave():
cave = ''
while cave != '1' and cave != '2':
print('Which cave will you go into? (1 or 2)')
cave = input()
return cave
def checkCave(chosenCave):
print('You approach the cave...')
time.sleep(2)
print('It is dark and spooky...')
time.sleep(2)
print('A large dragon jumps out in front of you! He opens his jaws and...')
print()
time.sleep(2)
friendlyCave = random.randint(1, 2)
if
chosenCave == str(friendlyCave):
print('Gives you his treasure!')
else:
print('Gobbles you down in one bite!')
playAgain =
'yes'
while playAgain
== 'yes' or playAgain == 'y':
displayIntro()
caveNumber = chooseCave()
checkCave(caveNumber)
print('Do you want to play again? (yes or no)')
playAgain = input()
Comments
Post a Comment