Why is this program printed twice?

I can not isolate the problem. It is assumed that the program takes two integers and converts them to scientific notation, and then multiplies them. However, he prints a scientific concept twice. However, it prints information twice.

def convert(s): print("You typed " + s) n=0 for c in s: n=n+1 if n==1: print("In scientific notation:"+str(c)+'.', end='') if n!=1: print(str(c),end='') print('X 10^'+str(len(s)-1)) return c def convert_product(u): n=0 for c in u: n=n+1 if n==1: print("Product in scientific notation "+c+'.', end='') if n!=1: print(c, end='') def main(): s=input("Please input your first number\n") t=input("Please input your second number\n") u=str(int(convert(s))*int(convert(t))) convert(s) convert(t) convert_product(u) print('X 10^' + str(len(s)+len(t)-2)) main() 
+4
source share
1 answer

You invoke the conversion on this line:

 u=str(int(convert(s))*int(convert(t))) 

And you again call the conversion of numbers:

 convert(s) convert(t) 

And the conversion function is print. So you have double prints.

+3
source

Source: https://habr.com/ru/post/1441031/


All Articles