Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dragon game code #1419

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions python codes/Simple Calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#---------------------CREATE VARIABLES------------------------
Operator = ""
Num1 = 0
Num2 = 0
while True:
#--------------------GET VALUES FROM THE USER--------------------
print("Enter the operator from the above list : \n","\t Addition = + \n","\t Substraction = - \n","\t Multiplication = * \n", "\t Division = / \n","\t Power = ** \n")
Num1 = int(input("Enter the number 1 : "))
Num2 = int(input("Enter the number 2 : "))
Operator = str(input("Enter the Operator : " ))
#----------------------SIMPLE FUNCTIONS---------------------------
def Addition (Num1,Num2):
"This for the addition of two numbers"
Ans = Num1+Num2
return Ans
def Substraction (Num1,Num2):
"This for the substraaction of two numbers"
Ans = Num1-Num2
return Ans

def Multiplication(Num1,Num2):
"This for the multiplication of two numbers"
Ans = Num1*Num2
return Ans

def Division (Num1,Num2):
"This for the division of two numbers"
Ans = Num1/Num2
return Ans

def Power (Num1,Num2):
"This for the power of two numbers"
Ans = Num1**Num2
return Ans

#----------------------PROCESS AND DISPLAY------------------------
if Operator == '+':
print ("The addition of the two numbers are :", Addition(Num1,Num2))
elif Operator == '-':
print ("The substraction of the two numbers are :", Substraction(Num1,Num2))
elif Operator == '*':
print ("The multiplication of the two numbers are :", Multiplication(Num1,Num2))
elif Operator == '/':
print ("The division of the two numbers are :", Division(Num1,Num2))
elif Operator == '**':
print ("The power of the two numbers are :", Power(Num1,Num2))
else:
print("Please enter the correct operator and opperands")




42 changes: 42 additions & 0 deletions python codes/dragongame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#import modules
import random
import time

#create varibles
try_again = ""
cave_list = ["1","2","3","4"]
#process and display
def display_intro():
print("""You are in the Kingdom of Dragons. In front of you,
you see four caves. In cave 1, the dragon is friendly
and will share his treasure with you. The dragon in cave 2
is hungry and will eat you on sight.
The dragon in cave 3 is friendly but doesn't have any treasure. And dragon in cave 4 is hungry and he got no treasure.""")

def choose_cave():
cave = ""
while cave not in cave_list:
cave = input("Which cave will you go into(1/2/3/4) : ")
return cave

def check_cave(choosen_cave):
caves = ["Gobbles you down!","Smiles, but no treasure","Gobbles you since he even doesn't even have any treasure"]
print("You approach the cave...")
time.sleep(2)
print("A large dragon jumps out in front of you! ")
print("He opens his jaws and ...")
time.sleep(2)
friendly_cave = random.randint(1,4)
if choosen_cave == str(friendly_cave):
print("Gives you his treasure!")
else:
random_cave = random.choice(caves)
print(str(random_cave))

while True:
display_intro()
cave_number = choose_cave()
check_cave(cave_number)
try_again = input("Do you want to try again ? (Y for yes / N for no) : ")
if try_again.lower() == "n":
break