1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Python Thread

Discussion in 'Programming' started by vexus, Oct 21, 2015.

  1. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    So I've really dug my teeth into Python recently (no pun intended) and I'm liking it so far. I know Python is one of the better known languages and easier to 'manipulate' and I like that. Gotta start somewhere, right? The only thing that irks me is the incessant indenting errors. If you don't indent correctly, your code will not work. Finally though, I've gotten the hang of it. It's actually pretty fun once you get a momentum going.

    I've only finally gotten the 'out-of-scope' occurrences in Python where I need to return a variable in order to use it in another function. Pretty easy stuff I know, I just never knew what the 'return' did in Python... or in any language for that matter.

    e.g.
    Code:
    def unpackCon():
      unpackConfirm = input("Unpack? [Y/N] ").lower()
      return unpackConfirm
    
    def unpackConScript():
      unpackConfirm = unpackCon()
    Anyone have any experience with Python? It'd be cool to learn any tricks for it, or any general guidelines and steps I should take to improve my knowledge about it. I've already completed Python the Hard Way, which was, in relation to the name, actually pretty easy. Functions messed me up at first but I got them later on.
     
  2. Sixx

    Sixx presidential #1 Legend

    Haven't picked up Python before, I think the indentation errors would really screw me over though.
    I recently wrote a mathematics program from scratch in Delphi and aw man my indents were all over the place.
    Code:
    program Project1;
    
    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      System.SysUtils;
    
    var answer:string;     // Declares global variables.
          num1:integer;
          num2:integer;
          num3:integer;
    
    
        procedure MenuCall;      // Calls for the menu.
        begin
          writeln(' ');
          writeln('Hello! Welcome to the program.');
          writeln('Which of the menu options would you like to call?');
          writeln(' ');
          writeln('1: Add two numbers.');
          writeln('2: Subtract two numbers');
          writeln('3: Multiply two numbers.');
          writeln('4: Divide two numbers.');
          writeln('5: Exit the program.');
          readln(answer);
        end;
    
        procedure DivNumbers;          // Divides the numbers.
          var temp, no1, no2:integer;
          begin
            writeln('Enter a number.');
            readln(no1);
            writeln('Enter a second.');
            readln(no2);
            temp:= no1 DIV no2;
            writeln('The answer is ',temp);
          end;
    
         procedure MulNumbers;                  // Multiplies the numbers.
          var temp, no1, no2:integer;
          begin
            writeln('Enter a number.');
            readln(no1);
            writeln('Enter a second.');
            readln(no2);
            temp:= no1 * no2;
            writeln('The answer is ',temp);
          end;
    
        procedure AddNumbers(num1,num2:integer);  // Adds numbers, passes variable by reference.
          var temp:integer;
          begin
            temp:= num1 + num2;
            writeln('The answer is ',temp);
          end;
    
        procedure SubNumbers(var num1, num2:integer);                   // Subtracts the numbers.
          var temp:integer;
          begin
            temp:= num1 - num2;
            writeln('The answer is ',temp);
          end;
    
    
        procedure Exit;               // Exits the program.
          var ans:string;
          begin
            writeln('Are you sure you would like to leave the program?');
            readln(ans);
              if (ans = 'Yes') or (ans = 'y') then
            readln
          else
            MenuCall;
          end;
    
    begin
    repeat
      MenuCall;
      if (answer = '1') then
        begin
          writeln('Enter a number.');
          readln(num1);
          writeln('Enter your second number.');
          readln(num2);
          AddNumbers(num1,num2);
        end
      else if (answer = '2') then
        begin
          writeln('Enter a number.');
          readln(num1);
          writeln('Enter your second number.');
          readln(num2);
          SubNumbers(num1,num2);
        end
      else if (answer = '3') then
        begin
          MulNumbers;
        end
      else if (answer = '4') then
        begin
          DivNumbers;
        end
      else if (answer = '5') then
        begin
          exit;
        end;
    until answer = '5' ;
    end.
    I recently wrote another very similar using functions instead of procedures, but I think my indentations were a little better on that.
    Good luck with it, though!
     
    • Informative Informative x 1
    • Friendly Friendly x 1
  3. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    Does Delphi have it's own IDEs?
     
  4. Sixx

    Sixx presidential #1 Legend

  5. prom queen

    prom queen Guest

    if i could code i would. somebody teach me
     
    • Funny Funny x 1
  6. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    Yes, def is function.

    Code:
    # Define the function.
    def myFunction():
      x = 4
    
      if x == 4:
      print ("this")
    
    # Run the function.
    myFunction()
    
    Just yolo it and watch some YouTube videos.
     
    • Funny Funny x 1
  7. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    Created another goodie in Python for helping me in Chem. I also did it in Lua, JS, and Ruby, and I tried doing it in C++ but C++ hates strings so

    Code:
    import time
    import os
    
    # Percent Composition Calculator
    
    os.system('cls')
    # todo: clean up disgusting var names
    e1 = input("First element symbol: ")
    e1quant = input("First element quantity: ")
    e1mass = input("First element's AM: ")
    e2 = input("Second element symbol: ")
    e2quant = input("Second element quantity: ")
    e2mass = input("Second element's AM: ")
    int_e1mass = float(e1mass)
    int_e2mass = float(e2mass)
    int_e1quant = float(e1quant)
    int_e2quant = float(e2quant)
    
    fullCName = e1 + e1quant + e2 + e2quant
    firstCheck = input("Compound given is " + fullCName + ". Is this correct [Y/N]?: ")
    
    # todo: call lower function so there are no or operators
    if firstCheck== "y" or "Y":
       e1aftermult = int_e1mass * int_e1quant
       e2aftermult = int_e2mass * int_e2quant
       mmass = e1aftermult + e2aftermult
       str_mmass = str(mmass)
       print("Molar Mass: " + str_mmass + "g/mol")
       # Find % composition of Element 1.
       e1pc = e1aftermult / mmass * 100
       sf = str(e1pc)
       e2pc = e2aftermult / mmass * 100
       sf2 = str(e2pc)
       print ("Percent composition of " + fullCName + " is: " + e1 + " = " + sf + "%" + " ; " + e2 + " = " + sf2 + "%")
    
    # todo: call lower function so there are no or operators
    # todo: run loop to ask element info again if firstCheck gets N
    elif firstCheck == "N" or "n":
       print ("Restart program.")
    
     
  8. I dont understand any of these
     
    • Like Like x 1
    • Disagree Disagree x 1
  9. then don't post
     
    • Like Like x 1
    • Funny Funny x 1
  10. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    • Like Like x 1
    • Like Like x 1

Previous Readers (Total: 0)