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 (Zephyr)
  • 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 858 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ęśliwy
    szczęśliwy
    szczęśliwy
    Coders Русский(Russian) Classical Pianists Pythons the goat Learning Polish
    wrote on last edited by szczęśliwy
    #1

    my stupid-[censored] 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? VGMoose 2 Replies Last reply
    1
    • szczęśliwy szczęśliwy

      my stupid-[censored] 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?
      A Former User?
      A Former User
      wrote on last edited by [[global:former-user]]
      #2
         @danniltrifonov  Lol
      
      szczęśliwy 1 Reply Last reply
      0
      • A Former User? A Former User
           @danniltrifonov  Lol
        
        szczęśliwy
        szczęśliwy
        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ęśliwy szczęśliwy

          @KG3M0 said in coding...:

             @danniltrifonov  Lol
          
          user_input = " "
          
          if user_input == "Lol":
            print("suppppp")
          else:
            print("Idk")
          
          A Former User?
          A Former User?
          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 [censored] Dumb Tho
          
          1 Reply Last reply
          0
          • szczęśliwy szczęśliwy

            my stupid-[censored] 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)
            
            VGMoose
            VGMoose
            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ęśliwy 1 Reply Last reply
            0
            • pwsincd
              pwsincd
              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ęśliwy 1 Reply Last reply
              1
              • VGMoose 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ęśliwy
                szczęśliwy
                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
                • pwsincd 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ęśliwy
                  szczęśliwy
                  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

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  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