+ 1
Multiple string values
Input: 2 2 (two numbers with space) Output: 4 how to make it work without imort additional modules? (The entered numbers can be multi-digit (123 12 75533, etc.).)
12 Respuestas
+ 5
there is a builtin function to multiply elements of a list, but he is asking to use no imports
import math
print(math.prod([2,2,3,])) # result is 12
+ 5
Sergey , your code is perfect, no need to rework it. 👍
+ 2
Илья Мирошник I'd advise against using eval on input without any validation because it poses a security risk. This just a training exercise of course, but suggesting it shouldn't go without a warning about the risks. At least don't use it on untrusted input in a productive application.
More explanation:
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-eval-function/#minimizing-the-security-issues-of-eval
Also you are making assumptions about input that can be false
And it is harder to read / understand the purpose than math.prod()
+ 1
Not sum(), need multiple(*)....
+ 1
Works, but not very elegantly 😂
https://code.sololearn.com/c8M7QShM3ZRS/?ref=app
+ 1
Lothar you are right, my wording was not correct
+ 1
Just eval text:
print(eval(str(input()).replace(" ","*")))
0
There is no inbuilt function to multiply list elements, so you have to do it yourself in a loop.
If you can't get it to work have a look at this link:
https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-multiply-numbers-list-3-different-ways/
0
Илья Мирошник
Лучшее решение, спасибо!
print(eval(str(input()).replace(" ","*")))
0
eval can be made a programming language itself lol
0
LOL its just fun man