Uom python course 1 assignment part 1

IT kolla

Active member
  • Mar 8, 2022
    171
    168
    43
    මේකේ පලවෙනි හෝ දෙවනි input එකට integer එකට අමතරව $ වගේ එකක් දැම්මොත් අවුල් යනවා. අපිට පුලුවන්ද එකම ඉන්පුට් එකට දාන integer එකයි character එකයි print කරගන්න. උඩ ටෙස්ට් 3ම ගොඩ දාගත්තා.

    assignment 1.JPG

    assignment 2.JPG
     
    • Like
    Reactions: Kfire

    olu bakka

    Well-known member
  • Aug 18, 2011
    22,115
    22,544
    113
    පැහැදිලි නෑ උබ කියන එක

    පොඩ්ඩක් explain කරොත් විසදුමක් කියන්න පුලුවන් වෙයි
    ------ Post added on May 7, 2022 at 10:28 PM
     

    0x9

    Well-known member
  • Mar 18, 2015
    541
    836
    93
    මම දාපු answer එක, මේක 100% accurate නෑ එත් test pass වෙනවා
    Python:
    def get_user_input():
        a = input("Enter first number: ")
        print(a)
        if(a=='#'):
            return -1
        try:
            fa=float(a)
        except ValueError:
            return None
        b = input("Enter second number: ")
        print(b)
        if(b=='#'):
            return -1
        try:
            fb=float(b)
        except ValueError:
            return None
        return fa,fb
       
    def add(a,b):
        print(float(a), "+", float(b), "=", float(a)+float(b))
        return
       
    def subtract(a,b):
        print(float(a), "-", float(b), "=", float(a)-float(b))
       
    def multiply(a,b):
        return a*b
       
    def divide(a,b):
        try:
            print(float(a), "/", float(b), "=", float(a)/float(b))
        except ZeroDivisionError:
            print("float division by zero")
            print(float(a), "/", float(b), "=", "None")
        except ValueError:
            pass
        return
       
    def power(a,b):
        return a+b
       
    def remainder(a,b):
        return a+b
    
    
    def select_op(choice):
        if(choice == "#"):
            return -1
        elif(choice == "+"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            add(a,b)
        elif(choice == "-"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            subtract(a,b)
        elif(choice == "/"):
            Z = get_user_input()
            if(Z==None):
                return
            a,b = Z
            divide(a,b)
    
    
    
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
    
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if(select_op(choice) == -1):
        #program ends here
        print("Done. Terminating")
        exit()


    1.png

    2.png

    3.png

    4.png
     

    olu bakka

    Well-known member
  • Aug 18, 2011
    22,115
    22,544
    113
    මම දාපු answer එක, මේක 100% accurate නෑ එත් test pass වෙනවා
    Python:
    def get_user_input():
        a = input("Enter first number: ")
        print(a)
        if(a=='#'):
            return -1
        try:
            fa=float(a)
        except ValueError:
            return None
        b = input("Enter second number: ")
        print(b)
        if(b=='#'):
            return -1
        try:
            fb=float(b)
        except ValueError:
            return None
        return fa,fb
      
    def add(a,b):
        print(float(a), "+", float(b), "=", float(a)+float(b))
        return
      
    def subtract(a,b):
        print(float(a), "-", float(b), "=", float(a)-float(b))
      
    def multiply(a,b):
        return a*b
      
    def divide(a,b):
        try:
            print(float(a), "/", float(b), "=", float(a)/float(b))
        except ZeroDivisionError:
            print("float division by zero")
            print(float(a), "/", float(b), "=", "None")
        except ValueError:
            pass
        return
      
    def power(a,b):
        return a+b
      
    def remainder(a,b):
        return a+b
    
    
    def select_op(choice):
        if(choice == "#"):
            return -1
        elif(choice == "+"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            add(a,b)
        elif(choice == "-"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            subtract(a,b)
        elif(choice == "/"):
            Z = get_user_input()
            if(Z==None):
                return
            a,b = Z
            divide(a,b)
    
    
    
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
    
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if(select_op(choice) == -1):
        #program ends here
        print("Done. Terminating")
        exit()


    View attachment 170146
    View attachment 170148
    View attachment 170149
    View attachment 170150
    කොපි කරල දාලා පාස් වෙන්න එපා හැබැයි. තමන්ම debug කරගන්න බලන්න.
     
    • Like
    Reactions: 0x9

    IT kolla

    Active member
  • Mar 8, 2022
    171
    168
    43
    TH
    මම දාපු answer එක, මේක 100% accurate නෑ එත් test pass වෙනවා
    Python:
    def get_user_input():
        a = input("Enter first number: ")
        print(a)
        if(a=='#'):
            return -1
        try:
            fa=float(a)
        except ValueError:
            return None
        b = input("Enter second number: ")
        print(b)
        if(b=='#'):
            return -1
        try:
            fb=float(b)
        except ValueError:
            return None
        return fa,fb
      
    def add(a,b):
        print(float(a), "+", float(b), "=", float(a)+float(b))
        return
      
    def subtract(a,b):
        print(float(a), "-", float(b), "=", float(a)-float(b))
      
    def multiply(a,b):
        return a*b
      
    def divide(a,b):
        try:
            print(float(a), "/", float(b), "=", float(a)/float(b))
        except ZeroDivisionError:
            print("float division by zero")
            print(float(a), "/", float(b), "=", "None")
        except ValueError:
            pass
        return
      
    def power(a,b):
        return a+b
      
    def remainder(a,b):
        return a+b
    
    
    def select_op(choice):
        if(choice == "#"):
            return -1
        elif(choice == "+"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            add(a,b)
        elif(choice == "-"):
            Z = get_user_input()
            if(Z==None):
                return
            elif(Z==-1):
                return -1
            a,b = Z
            subtract(a,b)
        elif(choice == "/"):
            Z = get_user_input()
            if(Z==None):
                return
            a,b = Z
            divide(a,b)
    
    
    
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
    
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if(select_op(choice) == -1):
        #program ends here
        print("Done. Terminating")
        exit()


    View attachment 170146
    View attachment 170148
    View attachment 170149
    View attachment 170150
    Thank you for the answer.
    mama menna meka demmama hari giya kalin. eth dn EOFError kiyala ekk enwane.


    a=input("Enter first number: ")
    print(a)
    a=float(a)

    b=input("Enter second number: ")
    print(b)
    b=float(b)
    assignment 3.JPG


    කොපි කරල දාලා පාස් වෙන්න එපා හැබැයි. තමන්ම debug කරගන්න බලන්න.
    thank you machan. ne mama eka hadagaththa try krla kohomahri. mama programming lokuwata krla ne.eka nisa lokuwata hithennema ne
    ------ Post added on May 7, 2022 at 11:18 PM
     

    olu bakka

    Well-known member
  • Aug 18, 2011
    22,115
    22,544
    113
    TH

    Thank you for the answer.
    mama menna meka demmama hari giya kalin. eth dn EOFError kiyala ekk enwane.


    a=input("Enter first number: ")
    print(a)
    a=float(a)

    b=input("Enter second number: ")
    print(b)
    b=float(b)
    View attachment 170159


    thank you machan. ne mama eka hadagaththa try krla kohomahri. mama programming lokuwata krla ne.eka nisa lokuwata hithennema ne
    ------ Post added on May 7, 2022 at 11:18 PM
    Ube code eka dammanan balanna tibba bn
     

    IT kolla

    Active member
  • Mar 8, 2022
    171
    168
    43
    Ube code eka dammanan balanna tibba bn


    while True:
    print("Select operation.")
    print("1.Add : + ")
    print("2.Subtract : - ")
    print("3.Multiply : * ")
    print("4.Divide : / ")
    print("5.Power : ^ ")
    print("6.Remainder: % ")
    print("7.Terminate: # ")
    print("8.Reset : $ ")

    def add(x,y):
    return x+y

    def substract(x,y):
    return x-y

    def multiply(x,y):
    return x*y

    def divide(x,y):
    return x/y

    def power(x,y):
    return x**y

    def remainder(x,y):
    return x%y


    # take input from the user
    choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
    print(choice)
    if choice == "#":
    #program ends here
    print("Done. Terminating")
    exit()
    if choice == "$":
    continue
    try:
    a=input("Enter first number: ")
    print(a)
    a=float(a)

    b=input("Enter second number: ")
    print(b)
    b=float(b)
    except:
    continue

    if choice == "+":
    print(a, "+", b, "=", add(a,b))

    elif choice == "-":
    print(a, "-", b, "=", substract(a,b))

    elif choice == "*":
    print(a, "*", b, "=", multiply(a,b))

    elif choice == "/":
    if b == 0.0:
    print("float division by zero")
    print(a, "/", b, "=" " None")
    else:
    print(a, "/", b, "=", divide(a,b))

    elif choice == '^':
    print(a, "^", b, "=", power(a,b))

    elif choice == "%":
    print(a, "%", b, "=", remainder(a,b))

    else :
    print("Unrecognized operation")



    meka thama machan mage code eka
     

    0x9

    Well-known member
  • Mar 18, 2015
    541
    836
    93
    TH

    Thank you for the answer.
    mama menna meka demmama hari giya kalin. eth dn EOFError kiyala ekk enwane.


    a=input("Enter first number: ")
    print(a)
    a=float(a)

    b=input("Enter second number: ")
    print(b)
    b=float(b)
    View attachment 170159


    thank you machan. ne mama eka hadagaththa try krla kohomahri. mama programming lokuwata krla ne.eka nisa lokuwata hithennema ne
    ------ Post added on May 7, 2022 at 11:18 PM

    temporary issue එකක් හරි code එක copy කරනකොට indentation අවුල් වෙලා වෙන්න පුළුවන්
    Question author's solution කියල complete answer එක අන්තිමට තිබ්බා .. එක මෙතැන දාන එක හරි නැති නිසා මම දැම්ම නෑ
     

    olu bakka

    Well-known member
  • Aug 18, 2011
    22,115
    22,544
    113
    while True:
    print("Select operation.")
    print("1.Add : + ")
    print("2.Subtract : - ")
    print("3.Multiply : * ")
    print("4.Divide : / ")
    print("5.Power : ^ ")
    print("6.Remainder: % ")
    print("7.Terminate: # ")
    print("8.Reset : $ ")

    def add(x,y):
    return x+y

    def substract(x,y):
    return x-y

    def multiply(x,y):
    return x*y

    def divide(x,y):
    return x/y

    def power(x,y):
    return x**y

    def remainder(x,y):
    return x%y


    # take input from the user
    choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
    print(choice)
    if choice == "#":
    #program ends here
    print("Done. Terminating")
    exit()
    if choice == "$":
    continue
    try:
    a=input("Enter first number: ")
    print(a)
    a=float(a)

    b=input("Enter second number: ")
    print(b)
    b=float(b)
    except:
    continue

    if choice == "+":
    print(a, "+", b, "=", add(a,b))

    elif choice == "-":
    print(a, "-", b, "=", substract(a,b))

    elif choice == "*":
    print(a, "*", b, "=", multiply(a,b))

    elif choice == "/":
    if b == 0.0:
    print("float division by zero")
    print(a, "/", b, "=" " None")
    else:
    print(a, "/", b, "=", divide(a,b))

    elif choice == '^':
    print(a, "^", b, "=", power(a,b))

    elif choice == "%":
    print(a, "%", b, "=", remainder(a,b))

    else :
    print("Unrecognized operation")



    meka thama machan mage code eka
    machan meka ara uda 0x9 dala thiyenw wage Elakiri eke code option eken danna python select krla. nattan indentation nati nisa hoyanna amaruyi.
     

    IT kolla

    Active member
  • Mar 8, 2022
    171
    168
    43
    machan meka ara uda 0x9 dala thiyenw wage Elakiri eke code option eken danna python select krla. nattan indentation nati nisa hoyanna amaruyi.
    Python:
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
      def add(x,y):
          return x+y
    
      def substract(x,y):
          return x-y
    
      def multiply(x,y):
          return x*y
    
      def divide(x,y):
          return x/y
    
      def power(x,y):
          return x**y
    
      def remainder(x,y):
          return x%y
     
     
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if choice == "#":
        #program ends here
        print("Done. Terminating")
        exit()
      if choice == "$":
        continue
      try:
        a=input("Enter first number: ")
        print(a)
        a=float(a)
            
        b=input("Enter second number: ")
        print(b)
        b=float(b)
      except:
       continue
    
      if choice == "+":
          print(a, "+", b, "=", add(a,b))
    
      elif choice == "-":
          print(a, "-", b, "=", substract(a,b))
    
      elif choice == "*":
          print(a, "*", b, "=", multiply(a,b))
    
      elif choice == "/":
          if b == 0.0:
              print("float division by zero")
              print(a, "/", b, "=" " None")
          else:
              print(a, "/", b, "=", divide(a,b))
          
      elif choice == '^':
          print(a, "^", b, "=", power(a,b))
    
      elif choice == "%":
          print(a, "%", b, "=", remainder(a,b))
    
      else :
          print("Unrecognized operation")
     

    olu bakka

    Well-known member
  • Aug 18, 2011
    22,115
    22,544
    113
    Python:
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
      def add(x,y):
          return x+y
    
      def substract(x,y):
          return x-y
    
      def multiply(x,y):
          return x*y
    
      def divide(x,y):
          return x/y
    
      def power(x,y):
          return x**y
    
      def remainder(x,y):
          return x%y
     
     
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if choice == "#":
        #program ends here
        print("Done. Terminating")
        exit()
      if choice == "$":
        continue
      try:
        a=input("Enter first number: ")
        print(a)
        a=float(a)
           
        b=input("Enter second number: ")
        print(b)
        b=float(b)
      except:
       continue
    
      if choice == "+":
          print(a, "+", b, "=", add(a,b))
    
      elif choice == "-":
          print(a, "-", b, "=", substract(a,b))
    
      elif choice == "*":
          print(a, "*", b, "=", multiply(a,b))
    
      elif choice == "/":
          if b == 0.0:
              print("float division by zero")
              print(a, "/", b, "=" " None")
          else:
              print(a, "/", b, "=", divide(a,b))
         
      elif choice == '^':
          print(a, "^", b, "=", power(a,b))
    
      elif choice == "%":
          print(a, "%", b, "=", remainder(a,b))
    
      else :
          print("Unrecognized operation")
    Awulak na wage bn...Aru kiwwa wage copy krddi aulak wenna ati
     

    IT kolla

    Active member
  • Mar 8, 2022
    171
    168
    43
    mokada machan prashne eka clear nene
    menna mehema EOFError kiyala awlak enawane me code eke?

    assignment 3.JPG


    code eka:

    Python:
    while True:
      print("Select operation.")
      print("1.Add      : + ")
      print("2.Subtract : - ")
      print("3.Multiply : * ")
      print("4.Divide   : / ")
      print("5.Power    : ^ ")
      print("6.Remainder: % ")
      print("7.Terminate: # ")
      print("8.Reset    : $ ")
     
      def add(x,y):
          return x+y
    
      def substract(x,y):
          return x-y
    
      def multiply(x,y):
          return x*y
    
      def divide(x,y):
          return x/y
    
      def power(x,y):
          return x**y
    
      def remainder(x,y):
          return x%y
     
     
      # take input from the user
      choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
      print(choice)
      if choice == "#":
        #program ends here
        print("Done. Terminating")
        exit()
      if choice == "$":
        continue
      try:
        a=input("Enter first number: ")
        print(a)
        a=float(a)
            
        b=input("Enter second number: ")
        print(b)
        b=float(b)
      except:
       continue
    
      if choice == "+":
          print(a, "+", b, "=", add(a,b))
    
      elif choice == "-":
          print(a, "-", b, "=", substract(a,b))
    
      elif choice == "*":
          print(a, "*", b, "=", multiply(a,b))
    
      elif choice == "/":
          if b == 0.0:
              print("float division by zero")
              print(a, "/", b, "=" " None")
          else:
              print(a, "/", b, "=", divide(a,b))
          
      elif choice == '^':
          print(a, "^", b, "=", power(a,b))
    
      elif choice == "%":
          print(a, "%", b, "=", remainder(a,b))
    
      else :
          print("Unrecognized operation")
     

    IT kolla

    Active member
  • Mar 8, 2022
    171
    168
    43
    temporary issue එකක් හරි code එක copy කරනකොට indentation අවුල් වෙලා වෙන්න පුළුවන්
    Question author's solution කියල complete answer එක අන්තිමට තිබ්බා .. එක මෙතැන දාන එක හරි නැති නිසා මම දැම්ම නෑ
    ai kiyala thama hithagnna bene mata