diff --git a/myDoc/1. working_with_string.py b/myDoc/1. working_with_string.py new file mode 100644 index 0000000000..e149d58444 --- /dev/null +++ b/myDoc/1. working_with_string.py @@ -0,0 +1,34 @@ +# Working With String +print("Vincent Adeniji") # Horizontal +print("Vincent\Adeniji") # Back Slash +print("Vincent\nAdeniji") # New Line / Vertical +print("Vincent\'Adeniji") # +print("Vincent\"Adeniji") # + +# String Variable +name = "Vincent Adeniji" +print(name) + +# Concatination +name = "Vincent Adeniji \n" +school = "Lambda School" +print(name + school) + +# Function - a block of code that would perform a specific operation - modify, get info +school = 'Lambda Academy' +upperSchool = 'LAMBDA' +lowerSchool = 'lambda' + +print(school.upper(), '22') # Make the string UpperCase +print(school.upper().isupper(), '23') # Make the string UpperCase, is the String UpperCase? output: True +print(school.lower(), '24') +print(school.lower().islower(), '25') +print(school.isupper(), '26') +print(school.islower(), '27') +print(upperSchool.isupper(), '28') +print(lowerSchool.islower(), '29') + +print(len(school), 'length') # Length of the string +print(school[0]) # print the first letter +print(school.index('Lambda')) # Shows the index of the string. Note: only output the index of the first letter in the variable +print(school.replace('Academy', 'School')) # Replace diff --git a/myDoc/10. Return_Statement.py b/myDoc/10. Return_Statement.py new file mode 100644 index 0000000000..54891304cc --- /dev/null +++ b/myDoc/10. Return_Statement.py @@ -0,0 +1,7 @@ +# Return information from function + +def cube(num): + return int(num) ** 3 + +result = cube(2) +print(result) \ No newline at end of file diff --git a/myDoc/11. If_Statement.py b/myDoc/11. If_Statement.py new file mode 100644 index 0000000000..9d55c081e9 --- /dev/null +++ b/myDoc/11. If_Statement.py @@ -0,0 +1,22 @@ +Mahiya = "Crush" +crush = Mahiya +print(Mahiya) + +if len(Mahiya) > len(crush) or 2: # If one condition is true + print("I love you Apu") +elif Mahiya == "crush" or crush: + print("I still love you apu") +elif crush == Mahiya: + print("I will always love you apu") +else: + print("Where's Apuuu") + + +if Mahiya == crush and "Crush": # If both condition is true + print("I love you a lot apu") + + +if Mahiya == "Crush" and not(crush): # This won't output because crush is Mahiya, but we are saying it isn't + print("I so much Love you Apu") +else: + print("Always love you apu") \ No newline at end of file diff --git a/myDoc/12. If_Statement_and_comparison.py b/myDoc/12. If_Statement_and_comparison.py new file mode 100644 index 0000000000..6fb9cf2b8f --- /dev/null +++ b/myDoc/12. If_Statement_and_comparison.py @@ -0,0 +1,10 @@ +# Maximum number +def max_num(num1, num2, num3): + if num1 >= num2 and num1 >= num3: + return num1 + elif num2 >= num1 and num2 >= num3: + return num2 + else: + return num3 + +print(max_num(1, 2, 3)) \ No newline at end of file diff --git a/myDoc/13. Building_A_Better_Calculator.py b/myDoc/13. Building_A_Better_Calculator.py new file mode 100644 index 0000000000..ac7d618739 --- /dev/null +++ b/myDoc/13. Building_A_Better_Calculator.py @@ -0,0 +1,19 @@ +num1 = float(input('Enter First Number: ')) +operator = input('Enter operator: ') +num2 = float(input('Enter Second Number: ')) + + +if operator == '+': + print(num1 + num2) +elif operator == '-': + print(num1 - num2) +elif operator == '*': + print(num1 * num2) +elif operator == '/': + print(num1 / mum2) +elif operator == '%': + print(num1 % num2) +elif operator == '^': + print(num1 ** num2) +else: + print("Invalid Operator") diff --git a/myDoc/14. Dictionaries.py b/myDoc/14. Dictionaries.py new file mode 100644 index 0000000000..e9bb6d8be0 --- /dev/null +++ b/myDoc/14. Dictionaries.py @@ -0,0 +1,13 @@ +# Special Structure +# Allows us to store information in Key Value Pairs + + +monthConversion = { + "Jan": "January", + "Feb": "February", + "Mar": "March", + "Apr": "April", +} + +print(monthConversion['Jan']) +print(monthConversion.get("Feb")) \ No newline at end of file diff --git a/myDoc/15. While_Loop.py b/myDoc/15. While_Loop.py new file mode 100644 index 0000000000..106017175e --- /dev/null +++ b/myDoc/15. While_Loop.py @@ -0,0 +1,6 @@ +i = 1 +while i <= 10: + print(i) + i += 1 + +print("dONE") \ No newline at end of file diff --git a/myDoc/16. Building_Guessing_Game.py b/myDoc/16. Building_Guessing_Game.py new file mode 100644 index 0000000000..0c8d4cad68 --- /dev/null +++ b/myDoc/16. Building_Guessing_Game.py @@ -0,0 +1,17 @@ +secret_word = "Apu" +guess = "" +guess_count = 0 +guess_limit = 3 +out_of_luck = False + +while guess != secret_word and not(out_of_luck): + if guess_count < guess_limit: + guess = input('Enter Guess: ') + guess_count += 1 + else: + out_of_luck = True + +if out_of_luck: + print('Uh-oh!!! You Lose') +else: + print("You Win") diff --git a/myDoc/17. For_Loop.py b/myDoc/17. For_Loop.py new file mode 100644 index 0000000000..a9f15488cf --- /dev/null +++ b/myDoc/17. For_Loop.py @@ -0,0 +1,31 @@ +# + +for letter in "Lambda Academy": + print(letter) # Print all text in lamda academy + + +# + +crushes = ["Apu", "Sis", "Love"] + +for crush in crushes: + print(crush) + +# index of 10 +# Note index start from 0-9 + + +for index in range(10): + print(index) + +# range from 3 - 10 + +for index in range(3, 10): + print(index) + +# Using range with Variable +crushes = ['Apu', 'Love', 'Beautiful'] # Variable + +length = len(crushes) # Length Variable +for crush in range(length): # set a new Variable called crush and check the range of the length + print(crushes[crush]) # Output the range of the crushes names \ No newline at end of file diff --git a/myDoc/18. Exponential_Function.py b/myDoc/18. Exponential_Function.py new file mode 100644 index 0000000000..6a0cea8d58 --- /dev/null +++ b/myDoc/18. Exponential_Function.py @@ -0,0 +1,11 @@ +def raise_to_num(base_pow, pow_num): # First create a function with two parameter + result = 1 # We set a variable to one for the iteration, 1 * anything will always give us anything + for i in range(pow_num): # Now we create a variable and set it in range of the second paremeter + result = result * base_pow # and we use the result for the actual base. for example, let the base = 100, range = 3 + # 100 * result = 100, that is 1. the loop still need to go up 2 more times + # now result is 100, the second time will be 100 * 100 = 10,000 one more to go + # result now is 10,000. 10,000 * 100 = 1,000,000. + # Note the base remain the same. + return result # Now we return the result which is now 1,000,000. + # After a return statement we can't do anything except printing +print(raise_to_num(100,3)) # Now we print the call function diff --git a/myDoc/19. 2D_List_and_Nested_Loops.py b/myDoc/19. 2D_List_and_Nested_Loops.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/myDoc/2. working_with_numbers.py b/myDoc/2. working_with_numbers.py new file mode 100644 index 0000000000..312f373012 --- /dev/null +++ b/myDoc/2. working_with_numbers.py @@ -0,0 +1,57 @@ +# Print the actual number +print(2) # Whole Number +print(2.2) # Decimal Number +print(-2) +print(-2.2) + +# Arithmetics +print(2 + 2) # Plus +print(2 + 2.2) + +print(2 * 2 ) # Multiplication +print(2 * -2) + +print(2 * 2 + 2) +print(2 * (2 + 2)) # Parenthesis + +print(10 % 3) # Modulos gives the remainder, 10/3 remains 1 + +# Store Number inside a Variable + +num = 7 +print(num) + +# Convert Number to string +# Note you can't use number and string together, so you need to convert the number to string +print(str(num)) #Note, the actual number is now string +print(str(num) + " is the first letter of my name") + +# Absolute Value +num = -4, -4.34 +print(abs(num[0]), abs(num[1])) + +# raise to Power +num = 5 +print(pow(num, 2)) + +# Maximum Number +print(max(num, 2, 4)) + +# Mininum Number +print(min(num, 2, 4)) + +# Round Number +num = 4.1 +print(round(num)) + +# Floor Number. Note: this will remove any .int +# Note: you need to import math to use code below +from math import * + +print(floor(num)) + +# Ceil Number. Round the number as long as there's int above 0 +print(ceil(num)) + +# Square Root of a number +print(sqrt(num)) \ No newline at end of file diff --git a/myDoc/3. getting_input_from_users.py b/myDoc/3. getting_input_from_users.py new file mode 100644 index 0000000000..3be422b318 --- /dev/null +++ b/myDoc/3. getting_input_from_users.py @@ -0,0 +1,4 @@ +# Input. Allow you to type what you want +name = input("Enter your name: ") +lname = input("Enter your last name: ") +print("I'm " + name + lname + " !") \ No newline at end of file diff --git a/myDoc/4. building_calculator.py b/myDoc/4. building_calculator.py new file mode 100644 index 0000000000..853f5a7c77 --- /dev/null +++ b/myDoc/4. building_calculator.py @@ -0,0 +1,13 @@ +# Addition +num1 = input("Enter the first number: ") +num2 = input("Enter the second number: ") +result = float(num1) + float(num2) #note: int will look for a whole number not float. + +print(result) + +# Subtraction +num1 = input("Enter the first number: ") +num2 = input("Enter the second number: ") +result = float(num1) - float(num2) #note: int will look for a whole number not float. + +print(result) \ No newline at end of file diff --git a/myDoc/5. Mad_Lib_Game.py b/myDoc/5. Mad_Lib_Game.py new file mode 100644 index 0000000000..ab4d1ea1b9 --- /dev/null +++ b/myDoc/5. Mad_Lib_Game.py @@ -0,0 +1,8 @@ +color = input("Enter a color: ") +pnoun = input("Enter a noun: ") +celebrity = input("Enter a celebrity: ") + + +print(f"Roses Are {color}") +print(f"{pnoun} Are blue") +print(f"I Love You, {celebrity}") \ No newline at end of file diff --git a/myDoc/6. List.py b/myDoc/6. List.py new file mode 100644 index 0000000000..c66c7b429b --- /dev/null +++ b/myDoc/6. List.py @@ -0,0 +1,12 @@ +# Mutable +friends = ["Big", "Bang", "Apu", 2, False] + +print(friends) +print(friends[1]) +print(friends[-5]) +print(friends[2:]) # from index 2 to rest of the friends +print(friends[2:3]) # print all the element from 2 and up to, but not including 3 + +# Modify +friends[2] = "Crush" +print(friends) \ No newline at end of file diff --git a/myDoc/7. List_Function.py b/myDoc/7. List_Function.py new file mode 100644 index 0000000000..cfb2b92fa9 --- /dev/null +++ b/myDoc/7. List_Function.py @@ -0,0 +1,64 @@ +numbers = [1, 2, 3, 4, 5, 6] +crush = ["Apu", "Friend"] + +print(numbers) +print(crush) + +# Extend add two list together +# Note: you can add the same list +crush.extend(crush) +print(crush) + +numbers.extend(crush) +print(numbers) + +# Append add a specific info +# Note: add item at the end of the list +crush = ["Apu", "Friend"] + +crush.append("Love") +print(crush) + +# Insert to anywhere on the index +# Note: insert add new item to any index on the list and shift the previous index to the front +# for example ex = [Foo, Bar]. ex.insert(1, 'bang'). ex = [Foor, Bang, Bar] +crush.insert(1, 'Sis') +print(crush) + +# Remove the item from the list +# Note: you can remove using the variable array or the of the item +crush.remove(crush[1]) +crush.remove("Friend") +print(crush) + +# Clear remove everything from the list +crush.clear() +print(crush, 'cleared') + +# POP remove the last item off the list +# Note: if you print the function you will get what got poped +crush = ["Apu", "Sis", "Love"] +crush.pop() +print(crush.pop()) # Print and remove last item +print(crush) + +# Count + +crush = ["Apu", "is", "Beautiful"] +crush.extend(crush) +print(crush.count("Apu")) # Output 2\ +print(crush) + +# Sort +# Note: sort in ascending order +crush.sort() +print(crush) + +# Reverse the order in the list +crush.reverse() +print(crush) + +# Copy the list to another variable +crush = ['Apu', 'Lady M'] +sis = crush.copy() +print(sis) \ No newline at end of file diff --git a/myDoc/8. Tuples.py b/myDoc/8. Tuples.py new file mode 100644 index 0000000000..b02d1aef0f --- /dev/null +++ b/myDoc/8. Tuples.py @@ -0,0 +1,5 @@ +# Similar to a list +# Immutable - can't be change or modify +coordinates = (7, 9) +print(coordinates) # Output: 7, 9 +print(coordinates[0]) # Output: 7 \ No newline at end of file diff --git a/myDoc/9. Function.py b/myDoc/9. Function.py new file mode 100644 index 0000000000..745312fe98 --- /dev/null +++ b/myDoc/9. Function.py @@ -0,0 +1,15 @@ +# Hello +def say_hi(name, age): + print("Hello " + name + " I am " + str(age)) + +say_hi("Vincent", 23) +say_hi("Ryan", 33) + + +# Greetings +def Greetings(): + Greeting = "Hello " + name = input("Enter your name here: ") + print(Greeting + name) + +Greetings() diff --git a/myDoc/js_creating_new_method_with_jsfunction.js b/myDoc/js_creating_new_method_with_jsfunction.js new file mode 100644 index 0000000000..1da371b4c0 --- /dev/null +++ b/myDoc/js_creating_new_method_with_jsfunction.js @@ -0,0 +1,7 @@ +const lovers = { + name: "Apu", + age: parseInt("Sweet 16"), + +} + +console.log(lovers) \ No newline at end of file diff --git a/src/adv.py b/src/adv.py index c9e26b0f85..d6b7562c4b 100644 --- a/src/adv.py +++ b/src/adv.py @@ -1,7 +1,10 @@ -from room import Room - +# from room import Room +from room import (Room, valid_directions) +from player import Player # Declare all the rooms + + room = { 'outside': Room("Outside Cave Entrance", "North of you, the cave mount beckons"), @@ -38,6 +41,10 @@ # # Make a new player object that is currently in the 'outside' room. +player_name = input('Enter Name Here: ') +player = Player(player_name, room['outside']) + +print(room) # Write a loop that: # @@ -49,3 +56,25 @@ # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. + + +def is_direction(str): + return str in valid_directions + +print(f'Welcome {player.name}, press q at any time to quit') +print(f'You are currently {player.current_room.name}') +print(player.current_room.description) +current_room = player.current_room + +while True: + if current_room != player.current_room: + print(player.current_room) + current_room = player.current_room + current_room = player.current_room + user_input = input('Enter Your Direction? click n --> North, e --> East, s --> South or w --> West?: ') + if user_input == 'q': + break + elif is_direction(user_input): + player.move(user_input) + else: + print('Sorry that is not a valid command, please try again!') \ No newline at end of file diff --git a/src/player.py b/src/player.py index d79a175029..baf8656f2b 100644 --- a/src/player.py +++ b/src/player.py @@ -1,2 +1,20 @@ # Write a class to hold player information, e.g. what room they are in # currently. + +# from room import room + + +class Player: + def __init__(self, name, current_room): + self.name = name + self.current_room = current_room + + def move(self, direction): + new_room = getattr(self.current_room, f"{direction}_to") + if (new_room) is not None: + self.current_room = new_room + else: + print("Wrong Direction") + + def __str__(self): + return '{self.name} {self.current_room}'.format(self=self) \ No newline at end of file diff --git a/src/room.py b/src/room.py index 24c07ad4c8..b9aa00ae92 100644 --- a/src/room.py +++ b/src/room.py @@ -1,2 +1,25 @@ # Implement a class to hold room information. This should have name and -# description attributes. \ No newline at end of file +# description attributes. + + +valid_directions = ('n','s','e','w') + +class Room: + def __init__(self, name, description): + self.name = name + self.description = description + self.n_to = None + self.s_to = None + self.e_to = None + self.w_to = None + + def __str__(self): + return '{self.name} {self.description}'.format(self=self) + + def show_directions(self): + possible_directions = filter(lambda d: getattr(self, f"{d}_to") is not None, valid_directions) + return ", ".join(list(map(to_upper, possible_directions))) + + def print_welcome(self): + print(f'Welcome to {self.name}!') + print(f'{self.description}')