Search the Community

Showing results for tags 'programming'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • General
    • Show Us Your Creations
    • Blog
    • Recommended Reading
  • One Stop Programming Tutorials
    • Python Beginner Series
  • Programming Languages
    • Python
    • C++
    • C#
    • Arduino
    • Other Languages

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL







Found 3 results

  1. Apollo


    Made my first program using KJDElectronics' video tutorials of Python! This is the edited and cleaned up version i made after reading some advice about splitting up functions so that they can become more usable. Really happy with it and I'm still waiting on some more constructive criticism and ways to improve it! Here it is! """Calculator""" # Modules: import time # used as an illusion of loading for effects import random # used for random numbers in random_operation function import sys # used to exit program when needed # Operations: def add(num1, num2): # Defines addition return num1 + num2 def sub(num1, num2): # Defines subtraction return num1 - num2 def mul(num1, num2): # Defines multiplication return num1 * num2 def div(num1,num2): # Defines division try: return num1 / num2 except ZeroDivisionError: # Handles division by zero print("Division by zero cannot be done. Returning zero...") return 0 def exp(num1, num2): # Defines exponentiation return num1 ** num2 # Run operation function: def run_operation(operation, num1, num2): # Determine operation if operation == int("1"): print("Adding...") time.sleep(1) print(num1, "+", num2, "=", add(num1, num2)) elif operation == int("2"): print("Subtracting...") time.sleep(1) print(num1, "-", num2, "=", sub(num1, num2)) elif operation == int("3"): print("Multiplying...") time.sleep(1) print(num1, "*", num2, "=", mul(num1, num2)) elif operation == int("4"): print("Dividing...") time.sleep(1) print(num1, "/", num2, "=", div(num1, num2)) elif operation == int("5"): print("Raising to the power...") time.sleep(1) print(num1, "^", num2, "=", exp(num1, num2)) else: print("I don't understand") time.sleep(1) # Random operation function def random_operation(operation): for loop in range(4): # repeats random calculations 4 times valid_input = False while not valid_input: # while loop for invalid inputs try: operation = (input("What would you like me to do? add, subtract, multiply, divide, or " "raise to the power?...")) valid_input = True except ValueError: print("I don't understand...") time.sleep(1) # Defines random calculations random_num1 = random.randint(1, 100) random_num2 = random.randint(1, 100) if operation == str("add"): print("Randomizing") time.sleep(1) print(random_num1, "+", random_num2, "=", add(random_num1, random_num2)) time.sleep(1) elif operation == str("subtract"): print("Randomizing") time.sleep(1) print(random_num1, "-", random_num2, "=", sub(random_num1, random_num2)) time.sleep(1) elif operation == str("multiply"): print("Randomizing") time.sleep(1) print(random_num1, "*", random_num2, "=", mul(random_num1, random_num2)) time.sleep(1) elif operation == str("divide"): print("Randomizing") time.sleep(1) print(random_num1, "/", random_num2, "=", div(random_num1, random_num2)) time.sleep(1) elif operation == str("raise to the power"): print("Randomizing") time.sleep(1) print(random_num1, "^", random_num2, "=", exp(random_num1, random_num2)) time.sleep(1) else: print("I don't understand") time.sleep(1) print('\nPLEASURE CALCULATING WITH YOU.') time.sleep(1) print('GOODBYE...') time.sleep(1) sys.exit() # Exits program # Main calculator function: def main(): user_continue = True while user_continue: # Loops if user would like to restart program valid_input = False while not valid_input: # Loops if user enters an invalid input. Avoids error try: # Acquire user input num1 = int(input("What is number 1?...")) num2 = int(input("What is number 2?...")) operation = int(input("What would you like to do? 1. Addition, 2. Subtraction, 3. Multiplication, " "4. Division, 5. Exponentiation... Choose a number...")) valid_input = True except ValueError: # Handles any value errors print("invalid input, please try again...") time.sleep(1) run_operation(operation, num1, num2) time.sleep(1) # Ask if user wants to do random calculations or exit: restart_random = (str(input("Would you like to make more calculations? (y) for yes, anything else for no..." "\n OR would you like a random calculation?...(r) for random calculations then " "exit...anything else for no..."))) if restart_random != "y" and restart_random != "r": print("PLEASURE CALCULATING WITH YOU!") time.sleep(1) print("\nGOODBYE!") time.sleep(1) user_continue = False elif restart_random == "r": time.sleep(1) random_operation(operation) # intro-like sequence print('\n\n Calculator\n\n') time.sleep(1) print(' ---LOADING---\n') time.sleep(1) print('HI. I AM YOUR PERSONAL CALCULATOR BEEP BOOP. \n WHAT WOULD YOU LIKE ME TO CALCULATE?..\n') time.sleep(1) # call main function to start program main() # Turns my program into a module capable of being imported: if __name__ == '__calculator__': main()
  2. I was making a calculator that takes BEDMAS (Proper order of operations) into account. I'm very new (I just started today) but I managed to find a simple code for an ordinary calculator (like the ones that you find in phones, computers, etc) that works in a command line, and basing my code off of that. The problem is that I am trying to display the 'operationanswer2' of what I can assume is an integer or a variable (idk man, I'm not very good at this) but it keeps giving me a error message saying 'This inspection detects statements without any effect' He is the code. Due to fear of plagiarism I will only give you 3 parts of it that gives you how it's defined, and what I'm using to print it. operationanswer1 = (number_1 + number_2) if operation2 == '+' and operation1 == '+': operationanswer2 = (operationanswer1 + number_3) print!=operationanswer2 This is not the full code I am just afraid of plagiarism. Also I have school tomorrow so I will only be able to get back to you next evening.
  3. Hello Kevin, i am Goran Ivanov and i am currently 12 years old. So i am a total begginer, but i really am into programing, and i follow each step of you :). SO, i go on your python videos. I did everything on the first episode and it went great! So, i went on the 2nd episode. Everything was great there, but remember the part where you did myName = input("What is your name?") and you saved it. You went to cmd, did >>>python and it loaded saying Hello world What is your name? You answered saying Kevin and it went good. But the problem i am having is, that when i do everything and i save it, when i do >>>python it says this Hello world What is your name? and when i answer Goran, as that is my name, it sais that it is an error and that this name is not defined. I tried it with Kevin too. It didn't work. If you may tell me why that happends, and how i can fix it, that would be AWESOME! Ill post a picture of it too <3 Respectfuly, Sinsirely Goran Ivanov!