Kevin

Administrators
  • Content Count

    215
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by Kevin

  1. $myString = "14 Char String" echo strlen($myString ); //Prints 14 The `strlen` function is what you need
  2. Kevin

    Introducing Arduino

    I recommend starting with blink. Play with that and get the LED on the board to blink at different rates. Then move the LED onto a bread board with a resistor. Once you do that you should have your feet wet.
  3. Have you saved the file? That code is fine. Tested and got the following output: What is num1?1 What is num2?1 2 0 1 1.0 Process finished with exit code 0
  4. The input function ALWAYS returns a string. You are trying to do math on a string which is only allowed sometimes (you can see me discover something strange in one of the videos). You need to call the int function to convert from a string to an integer (parse).
  5. Kevin

    Question

    Perhaps try pressing the insert key on your keyboard? Not sure if that is the behavior you are referring to.
  6. Sure! See the code below with comments and some changed names to make it easier to understand. My bad on that originally. def main(): print(aGlobalVariable) def myPrintFunction(somethingToPrint): print(somethingToPrint) # This will not work because aGlobalVariable has not been defined yet #main() # Global variable. Typically defined at the top of the file but does not need to be. That is best practice aGlobalVariable = "This is a global variable." # Call the main function. This will print aGlobalVariable main() # Directly call the print function. This will print aGlobalVariable again to illistrate it is in fact global print(aGlobalVariable) # Define another variable otherVariable = "Something else" # This will print otherVariable by calling our myPrintFunction that then calls the print function. myPrintFunction(otherVariable) Let me know if you need me to clarify anything specifically. Kevin
  7. This tutorial covers an introduction to Object Oriented Programming in Python. After watching this video you should feel comfortable creating a basic class. This includes a constructor (__init__ function), and class methods. You should feel comfortable using parameters in a class constructor as well as class methods. Class methods should be able to access class properties using self. You should also understand that the 'self' variable needs to be passed into all methods within a class in python. Files: Starting Code: Start_Here.py rps.py: rps.py rps_annotated.py: rps_annotated.py Presentation - Introduction to Object Oriented Programming.pdf: Python_ObjectOrientedIntro.pdf Annotated Code: Starting Code:
  8. I know what you meant for this line to do, but what does it actually do? bothand = random.randint(0,3)
  9. Do you have another call to main() at the end of the function by any chance? Other than that I don't see anything that would cause that... Can you post your entire file? When posting code use the button at the top that looks like this "< >". That is the code button. You can paste your code in there and set the language to python in the bottom right. Makes it much easier to help troubleshoot.
  10. I plan to have the next video published by the end of the day on Saturday. Once its published there will be a thread here. Also make sure to subscribe on YouTube!
  11. Kevin

    Calculator

    Looks great! Your calculator() function is a bit lengthy. Think about different ways you can break up the code into smaller functional components. The smaller you make functions (by small I mean functions that do a single well defined thing) then the more you can reuse those functions. Great work!
  12. This is because the input function returns a string type. For example, if you type '25' into the console the variable myVar = '25' and not myVar = 25. There is a difference between a string (text) and a number (integer). Text can be a number but you have to tell the computer to convert it first. You need to use the int() function to parse your string into an integer. Change your code to this to see what is going on. print("Hello World") myName = input('What is your name?') myVar = input('How old are you?') print(myVar) myVar = int(myVar) print(myVar) print(myName) if(myName == "Kyle" and myVar == 25): print("Hello Kyle") else: print("Hello World") Note this will crash if you enter anything other than a number for your age.
  13. See my response in earlier. It is the Same issue.
  14. Kevin

    why am i wrong

    Code looks code good but nothing happening is very different than getting an error. If nothing is happening then your code probably is not running at all. If you code is running and you see "exit code 0" in the console that means your program is running and that is something. It looks like you may have missed calling your main function at the end of the file. This comment I posted on YouTube sums up what your program does withthout calling the main function:
  15. What the video in the first post in this thread. PyCharm is an IDE (integrated development environment). The video explains how to setup and install PyCharm. That will at least get you started using python and you can save your environment variable issues for another day.
  16. This tutorial covers an introduction of for loops, lists and dictionaries. The primary goal of this video is to tie up loose ends and introduce basic data structures so they can be used in future videos. This video also covers how to import existing code in your project to spread a program over multiple files for organization and code reuse purposes. After watching this video you should have a basic understanding of for loops, lists, and dictionaries. You should feel comfortable creating lists and dictionaries and appending new elements. You should also be able to loop over all of the items in a list or dictionary using a for loop. Note: This video is in a different format and all code was written before the video. The code used in the video is primarily in 'randomFun.py'. Changes were made to our 'calculator.py' (this is our renamed main.py from previous videos). Both files are attached here for you to reference while watching the video. Files: randomFun.py calculator.py Code
  17. Kevin

    python.exe

    Python files cannon be compiled into .exe files. There are some tools available however they are not widely supported. Your best but would be to create a native windows application (C# or C++) that launches your python application.
  18. In the output screenshot I see a space between in ") add" but I do not see a trailing space in the prompt "... and divide)". If you were adding a space that would cause that issue because " add" != "add"
  19. This should be taken care of during the install in the step where you select to create the environmental variables. Don't stress too much about not getting the environment variable setup as it is not strictly required if you use PyCharm.
  20. This tutorial covers an introduction to writing clean code. This video focuses on cleaning up our existing calculator program to make it more robust and easier to read. This video also introduces the for loop, loop control keywords "break," "continue" and introduces the "import" keyword to demonstrate time.sleep() and random.randint(). After watching this video you should be ready to start on the two challenges posed at the end of the video. Challenge 1: Random Calculator Modify the calculator program to use randint to run random calculations. Make this as random as you want so be creative!! Feel free to also use time.sleep() to give your program a more autonomous feel to it. Bonus points if you incorporate a for loop and loop control keywords. Remember to use the clean code strategies discussed in this video; if you have big blocks of code that look hard to read then try to fix it. Challenge 2: Rock, Paper, Scissors Game This idea was originally created by Zibzo and what he is posted here. Try to write clean code and note that what was posted by Zibzo has room for improvement given what we learned in this video.
  21. This tutorial covers exception handling in Python with try/except and introduces the concept of looping with the while loop. After watching this video you should feel conformable using the try except block to handle errors and using while loops. Source Code: def add(num1, num2): """Returns num1 plus num2.""" return num1 + num2 def sub(num1, num2): """Returns num1 minus num2.""" return num1 - num2 def mul(num1, num2): """Returns num1 times num2.""" return num1 * num2 def div(num1, num2): """Returns num1 divided by num2.""" return num1 / num2 def main(): """Allows user to run basic calculator operations with two numbers.""" validInput = False while not validInput: # Get user input try: num1 = int(input("What is number 1?")) num2 = int(input("What is number 2?")) operation = int(input("What do you want to do? 1. add, 2. subtract, 3. multiply, or 4. divide. Enter number: ")) validInput = True except: print("Invalid input. Try again.") # Determine operation if (operation == 1): print("Adding...") print(add(num1, num2)) elif (operation == 2): print("Subtracting...") print(sub(num1, num2)) elif (operation == 3): print("Multiplying...") print(mul(num1, num2)) elif (operation == 4): print("Dividing...") print(div(num1, num2)) else: print("I don't understand") main()
  22. Many. The goal is to get to a point where we can talk about application design and systems architecture. That is being able to create an application in python that connects to a database, integrates with other apps, and then provides its own service. After that I'll start over from square one in another language. Probably c# next.
  23. This tutorial covers declaring Boolean expressions and evaluating conditional expressions in python (if statement). After watching this video users should be able to create and evaluate Boolean expressions and use Boolean expressions in conditional operations (if statements).