Why this code returns an unexpected "None" ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Why this code returns an unexpected "None" ?

Code: vvod = input() x = vvod.split(" ") def sum(x): print(int(x[0]) + int(x[2])) def minus(x): print(int(x[0]) - int(x[2])) def mn(x): print(int(x[0]) * int(x[2])) def delit(x): print(int(x[0])/int(x[2])) def procent(x): print(int(x[0])/int(x[2])*100) def procent2(x): print(int(x[0])*int(x[2])/100) def stepen(x): print(int(x[0])**int(x[2])) if x[1] == "+": print(sum(x)) elif x[1] == "-": print(minus(x)) elif x[1] == "*": print(mn(x)) elif x[1] == ":": print(delit(x)) elif x[1] == "%": print(str(procent(x))+"%") print("Š²Š²Š¾Š“: x , % , y ") print("Š²Ń‹Š²Š¾Š“: сŠŗŠ¾Š»ŃŒŠŗŠ¾ % сŠ¾ŃŃ‚Š°Š²Š»ŃŠµŃ‚ x Š¾Ń‚ y") elif x[1] == "**": print(stepen(x)) print("Š²Š²Š¾Š“: чŠøсŠ»Š¾, ** , стŠµŠæŠµŠ½ŃŒ") elif x[1] == "%%": print(procent2(x)) print("Š²Š²Š¾Š“: чŠøсŠ»Š¾ , %% , ŠæрŠ¾Ń†ŠµŠ½Ń‚") print("Š²Ń‹Š²Š¾Š“: сŠŗŠ¾Š»ŃŒŠŗŠ¾ ŠæрŠ¾Ń†ŠµŠ½Ń‚ сŠ¾ŃŃ‚Š°Š²Š»ŃŠµŃ‚ Š¾Ń‚ чŠøсŠ»Š°") else: print("can't operate!")

29th Oct 2023, 8:03 PM
??????
?????? - avatar
3 Respostas
+ 2
None of the defined functions return a value. The main routine tries to print the return value from each function, but of course it has none to print. I recommend replacing the print statements that are inside the functions with return statements, and let the main code do all the printing. For example, def minus(x): return int(x[0]) - int(x[2])
29th Oct 2023, 9:36 PM
Brian
Brian - avatar
+ 2
Brian The given code will print the expected result except there is a None following. I made a code about return weeks before, but now decided to expand it to cover the issue ?????? is facing. https://code.sololearn.com/cVF03G3wAXBt/?ref=app
30th Oct 2023, 4:15 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
Wong Hei Ming you are correct. I did not mention that, as the OP did not seem confused about why the results were being printed.
30th Oct 2023, 4:57 AM
Brian
Brian - avatar