diff --git a/python codes/Simple Calculator.py b/python codes/Simple Calculator.py new file mode 100644 index 00000000..e62c3975 --- /dev/null +++ b/python codes/Simple Calculator.py @@ -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") + + + + diff --git a/python codes/dragongame.py b/python codes/dragongame.py new file mode 100644 index 00000000..84945c6f --- /dev/null +++ b/python codes/dragongame.py @@ -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