Python Forum
print logarithms todifferent base
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print logarithms todifferent base
#1

i have a homework and i am asking the user to input two numbers x and y:
from math import *
x=int(input('Please state a number for X: '))
y=int(input('Please state a number for Y: '))


then i need to calculate the log of x to the base of y.
here i have:
print(math.log(x,y))
but it returns errors " print(math.log(x,y))
NameError: name 'math' is not defined"

any ideas please?
Reply
#2
With from math import * you can just call the functions, e.g. log(x, y), or with import math use math.log(x, y).
I am trying to help you, really, even if it doesn't always seem that way
Reply
#3
(Oct-21-2017, 09:43 AM)atux_null Wrote: from math import *

I'll add that this is considered bad form and you should try to avoid using it.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020