Skip to content
  • Categories
  • Recent
  • Groups
  • Users
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • 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 (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Homebrew & Development
  3. Hombrewing Your Switch
  4. Development
  5. coding...

coding...

Scheduled Pinned Locked Moved Development
8 Posts 4 Posters 314 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.
  • szczęśliwyundefined Offline
    szczęśliwyundefined Offline
    szczęśliwy
    Coders Русский(Russian) Classical Pianists Pythons the goat Learning Polish
    wrote on last edited by szczęśliwy
    #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...

    A Former User? VGMooseundefined 2 Replies Last reply
    1
    • szczęśliwyundefined szczęśliwy

      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)
      
      A Former User? Offline
      A Former User? Offline
      A Former User
      wrote on last edited by A Former User
      #2
         @danniltrifonov  Lol
      
      szczęśliwyundefined 1 Reply Last reply
      0
      • A Former User? A Former User
           @danniltrifonov  Lol
        
        szczęśliwyundefined Offline
        szczęśliwyundefined Offline
        szczęśliwy
        Coders Русский(Russian) Classical Pianists Pythons the goat Learning Polish
        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...

        A Former User? 1 Reply Last reply
        0
        • szczęśliwyundefined szczęśliwy

          @KG3M0 said in coding...:

             @danniltrifonov  Lol
          
          user_input = " "
          
          if user_input == "Lol":
            print("suppppp")
          else:
            print("Idk")
          
          A Former User? Offline
          A Former User? 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
          • szczęśliwyundefined szczęśliwy

            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)
            
            VGMooseundefined Offline
            VGMooseundefined 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 browser petition! Or visit my site at vgmoose.dev.

            szczęśliwyundefined 1 Reply Last reply
            0
            • pwsincdundefined Offline
              pwsincdundefined 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

              szczęśliwyundefined 1 Reply Last reply
              1
              • VGMooseundefined 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

                szczęśliwyundefined Offline
                szczęśliwyundefined Offline
                szczęśliwy
                Coders Русский(Russian) Classical Pianists Pythons the goat Learning Polish
                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
                • pwsincdundefined 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

                  szczęśliwyundefined Offline
                  szczęśliwyundefined Offline
                  szczęśliwy
                  Coders Русский(Russian) Classical Pianists Pythons the goat Learning Polish
                  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