Как получить экспоненциальную операцию для правильной печати в Python?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как получить экспоненциальную операцию для правильной печати в Python?

Сообщение Anonymous »

Я строю приложение калькулятора, и оно включает в себя функцию, в которой пользователь может найти n -й корень базового номера. < /p>
Вот соответствующие части моего кода для этого вопроса: < /p>
def numberEntry1():
entry = float(input("Enter the first number:\n"))
return entry

def numberEntry2():
entry = float(input("Enter the second number:\n"))
return entry

def exponentialRoot(n1, n2):
return n1 ** (1/n2)
< /code>
mathDict = {
1: add,
2: subtraction,
3: multiplication,
4: division,
5: exponentialPower,
6: exponentialRoot,
}
< /code>
elif operationChoice == 6:
if choice1 < 0:
print(f"Evaluating the nth root of a negative number is not supported by this calculator.")
print(f"Try again!")
continue
result = mathDict[6](choice1, choice2)
if str(choice2)[-1] == "2":
print(f"The {choice2}nd root of {choice1} equals {result}")
< /code>
Basically what I'm trying to do here is to make the code print a statement depending on what the last character of choice2 is after it's converted into a string. For example, if choice 2 is "24" I want the print statement to say "The 24th root of {choice1} equals {result}" and if choice 2 is "22" I want it to say "The 22nd root of {choice1} equals {result}"
My current code just ends up not executing the print statement at all even though it still successfully executes the operation in the exponentialRoot function and returns the result.

Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-python
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»