Похожие чаты

For calculator case. (using it as an example). instead of

writing the four functions for add,subtract,multiply, divide. i would like to write a universal function that takes two operands and operator arguments and return the result for the expression def universal(operand1,operand2,operator): .how would i deal with the return expression?

3 ответов

8 просмотров

what do you expect the return should be?

do it..ask for userinput for operator

I've a suggestion for you.. Create a universal function and do the following... Pass the arguments in the order you want.. Like - number, number, operator (4,4, +) Then inside the universal function change the order to - Number, operator, number (4 + 4) And use eval() inside the universal function... Pass the modified argument order as a string to eval and you will get your result.

Похожие вопросы

Обсуждают сегодня

Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
We heading to 1.1$ 🤔?
CryptoBo$$
35
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
45
Сonst magicTgHTML = (text, entities) => { let processedText = text; let offsetShift = 0; entities.forEach(entity => { const { offset, length, type, url, ...
Андрей
1
кто-то пользуется компонентами rx ? как их лучше ставить, через OPM? (lazarus)
Iluha Companets
15
But what if some projects may have no sense financially but important from public relations point of view and overall adoption (which leads to more investors so more income). ...
Katu
3
Поставил генту, установил кланг, когда запускаю его не давая ему файла он выводит странную ошибку, в чем может быть дело? max@gentoo ~> clang /usr/bin/x86_64-pc-linux-gnu-ld.b...
молодой базз
8
Здравствуйте товарищи! решил всё таки поставить линукс. Порядок создание разделов /boot/efi 200МиБ; /boot 1000; подсистему / 80000; swap 8Гб Будет норм?
K2
19
How Will #Monero Be Attacked? First of all I want to tell you that this is not teaching the network attackers, the central regulators. They already know how to attack the net...
Li₿ΞʁLiøη
3
подскажите пожалуйста, как мне освободить результат записанный в переменную result? в чем проблема подскажите если МОЖЕТЕ?
Михаил Helper
28
Карта сайта