Thwa courses unlock wenwaමේ කෝස් එකෙන් පස්සෙ ඊළඟට මොනවද කරන්න ඕනෙ
Python ekai web dev ekai witarane thiyenne?Thwa courses unlock wenwa
Neneda? Mama dnna widiyata python advance ekakuth thiye. Mama hariyatama dnne ne. Krapu knk kiyai nedaPython ekai web dev ekai witarane thiyenne?
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()
කොපි කරල දාලා පාස් වෙන්න එපා හැබැයි. තමන්ම debug කරගන්න බලන්න.මම දාපු 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.මම දාපු 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 machan. ne mama eka hadagaththa try krla kohomahri. mama programming lokuwata krla ne.eka nisa lokuwata hithennema neකොපි කරල දාලා පාස් වෙන්න එපා හැබැයි. තමන්ම debug කරගන්න බලන්න.
Ube code eka dammanan balanna tibba bnTH
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
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
machan meka ara uda 0x9 dala thiyenw wage Elakiri eke code option eken danna python select krla. nattan indentation nati nisa hoyanna amaruyi.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.
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 atiPython: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")
menna mehema EOFError kiyala awlak enawane me code eke?mokada machan prashne eka clear nene
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")
ai kiyala thama hithagnna bene matatemporary issue එකක් හරි code එක copy කරනකොට indentation අවුල් වෙලා වෙන්න පුළුවන්
Question author's solution කියල complete answer එක අන්තිමට තිබ්බා .. එක මෙතැන දාන එක හරි නැති නිසා මම දැම්ම නෑ