Skip to content
  • Categories
  • Recent
  • Groups
  • Users
  • Tags
  • Popular
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Lumen)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Categories
  3. Homebrew & Development
  4. Hombrewing Your Switch
  5. Development
  6. coding...

coding...

Scheduled Pinned Locked Moved Development
8 Posts 4 Posters 143 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • danniltrifonovD Offline
    danniltrifonovD Offline
    danniltrifonov
    Coders Русский(Russian) i love cats Classical Pianists Sad Times did the dew Pythons the goat NOCTURNAL Generic BrowseDNS Chat slim shady gang THE LIT GANG Nathaniel follower resource center
    wrote on last edited by danniltrifonov
    #1

    my stupid-ass python calculator:

    from math import squareroot
    
    class Result():
      def __init__(self, result):
        self.result = result
    
    number_1 = int(input("Enter first number: "))
    number_2 = int(input("Enter second number: "))
    type = input("Enter operation type: 
    
    def calculate(no.1, no.2, type):
      if type == "+":
        answer = no.1 + no.2
        in_log = Result(answer)
        print(answer)
    
      elif type == "-":
        answer = no.1 - no.2
        in_log = Result(answer)
        print(answer)
    
      elif type == "*":
        answer = no.1 * no.2
        in_log = Result(answer)
        print(answer)
    
      elif type == "/":
        answer = no.1 / no.2
        in_log = Result(answer)
        print(answer)
    
      else:
        print("Please input correct numbers or type.")
    
     calculate(number_1, number_2, type)
    

    Do not go gentle into that goodnight...

    ? VGMooseV 2 Replies Last reply
    1
    • danniltrifonovD danniltrifonov

      my stupid-ass python calculator:

      from math import squareroot
      
      class Result():
        def __init__(self, result):
          self.result = result
      
      number_1 = int(input("Enter first number: "))
      number_2 = int(input("Enter second number: "))
      type = input("Enter operation type: 
      
      def calculate(no.1, no.2, type):
        if type == "+":
          answer = no.1 + no.2
          in_log = Result(answer)
          print(answer)
      
        elif type == "-":
          answer = no.1 - no.2
          in_log = Result(answer)
          print(answer)
      
        elif type == "*":
          answer = no.1 * no.2
          in_log = Result(answer)
          print(answer)
      
        elif type == "/":
          answer = no.1 / no.2
          in_log = Result(answer)
          print(answer)
      
        else:
          print("Please input correct numbers or type.")
      
       calculate(number_1, number_2, type)
      
      ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2
         @danniltrifonov  Lol
      
      danniltrifonovD 1 Reply Last reply
      0
      • ? A Former User
           @danniltrifonov  Lol
        
        danniltrifonovD Offline
        danniltrifonovD Offline
        danniltrifonov
        Coders Русский(Russian) i love cats Classical Pianists Sad Times did the dew Pythons the goat NOCTURNAL Generic BrowseDNS Chat slim shady gang THE LIT GANG Nathaniel follower resource center
        wrote on last edited by
        #3

        @KG3M0 said in coding...:

           @danniltrifonov  Lol
        
        user_input = " "
        
        if user_input == "Lol":
          print("suppppp")
        else:
          print("Idk")
        

        Do not go gentle into that goodnight...

        ? 1 Reply Last reply
        0
        • danniltrifonovD danniltrifonov

          @KG3M0 said in coding...:

             @danniltrifonov  Lol
          
          user_input = " "
          
          if user_input == "Lol":
            print("suppppp")
          else:
            print("Idk")
          
          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4
            @danniltrifonov said in [coding\.\.\.](/post/125471):
          

          @KG3M0 said in coding...:

             @danniltrifonov  Lol
          
          user_input = " "
          
          if user_input == "Lol":
            print("suppppp")
          else:
            print("Idk")
          
            Lol!, I Dont Know Much Expect For Spacing Lol `But I'm Trying`
          
          
              That Calculator Is Dead Ass Dumb Tho
          
          1 Reply Last reply
          0
          • danniltrifonovD danniltrifonov

            my stupid-ass python calculator:

            from math import squareroot
            
            class Result():
              def __init__(self, result):
                self.result = result
            
            number_1 = int(input("Enter first number: "))
            number_2 = int(input("Enter second number: "))
            type = input("Enter operation type: 
            
            def calculate(no.1, no.2, type):
              if type == "+":
                answer = no.1 + no.2
                in_log = Result(answer)
                print(answer)
            
              elif type == "-":
                answer = no.1 - no.2
                in_log = Result(answer)
                print(answer)
            
              elif type == "*":
                answer = no.1 * no.2
                in_log = Result(answer)
                print(answer)
            
              elif type == "/":
                answer = no.1 / no.2
                in_log = Result(answer)
                print(answer)
            
              else:
                print("Please input correct numbers or type.")
            
             calculate(number_1, number_2, type)
            
            VGMooseV Offline
            VGMooseV Offline
            VGMoose
            Admin
            wrote on last edited by VGMoose
            #5

            @danniltrifonov Looks good! If you use try...except blocks you can make it more error proof (eg. if someone types a string, or a tries to divide by zero)

            More info: https://www.w3schools.com/python/python_try_except.asp

            Sign the petition! Help us figure out the browser timeout.

            danniltrifonovD 1 Reply Last reply
            0
            • pwsincdP Offline
              pwsincdP Offline
              pwsincd
              Admin
              wrote on last edited by
              #6

              and also combine the regular occurances of code.. https://www.w3schools.com/python/python_functions.asp

              per calculation you could call a function to do the printing etc.. not a massive benefit in this scenario but a good lesson to learn

              "Don’t waste your words I don’t need anything from you / I don’t care where you’ve been or what you plan to do." - Ian Brown

              danniltrifonovD 1 Reply Last reply
              1
              • VGMooseV VGMoose

                @danniltrifonov Looks good! If you use try...except blocks you can make it more error proof (eg. if someone types a string, or a tries to divide by zero)

                More info: https://www.w3schools.com/python/python_try_except.asp

                danniltrifonovD Offline
                danniltrifonovD Offline
                danniltrifonov
                Coders Русский(Russian) i love cats Classical Pianists Sad Times did the dew Pythons the goat NOCTURNAL Generic BrowseDNS Chat slim shady gang THE LIT GANG Nathaniel follower resource center
                wrote on last edited by
                #7

                @VGMoose
                Alright, that makes sense. Then that way the whole app won't crash when someone enters a string like you said. Thank for the tip!

                Do not go gentle into that goodnight...

                1 Reply Last reply
                0
                • pwsincdP pwsincd

                  and also combine the regular occurances of code.. https://www.w3schools.com/python/python_functions.asp

                  per calculation you could call a function to do the printing etc.. not a massive benefit in this scenario but a good lesson to learn

                  danniltrifonovD Offline
                  danniltrifonovD Offline
                  danniltrifonov
                  Coders Русский(Russian) i love cats Classical Pianists Sad Times did the dew Pythons the goat NOCTURNAL Generic BrowseDNS Chat slim shady gang THE LIT GANG Nathaniel follower resource center
                  wrote on last edited by
                  #8

                  @pwsincd said in coding...:

                  and also combine the regular occurances of code.. https://www.w3schools.com/python/python_functions.asp

                  per calculation you could call a function to do the printing etc.. not a massive benefit in this scenario but a good lesson to learn

                  Yeah that seems like that would help. So your saying create a function that prints the results, and you just pass the values of the calculation into the function? Also thanks for the tip!

                  Do not go gentle into that goodnight...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Groups
                  • Users
                  • Tags
                  • Popular