469,271 Members | 1,785 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Least Square Method

I'm doing a program where students are asked to key in any value, lets a, and the program will automatically gives the answer of LOG10(A).

Then, student are asked to key in another value.Lets B

The programme will give the answer of LOG10(A)*B.

Below is the program that i write:

#program python kedua
print"Least Square Method"
#users are asked to key in the value
integer1=raw_input("insert the first value\n")
integer1= int(integer1)

c=raw_input (" enter a value for c:\n")
c=int(c)


while c>=1:
import math
math.log(c)
d=log10(c)("print %log10(c)==%d")%(c,d)

if c <=0:
print"error"

total=2*integer1*d

print"total"


The program cannot be run?
What is the right way to do it?
Thank You.
Sep 19 '06 #1
7 4310
bartonc
6,596 Expert 4TB
Because tab characters didn't come though, I can't see the whole structure so
I can't help with the least squares algorithm, but here are some pointers:


c=raw_input (" enter a value for c:\n")
c=int(c)

1) to allow floating point numbers to be entered use:
c = float(raw_input (" enter a value for c: "))
2) NOTE: space instead of newline looks better on the screen

while c>=1:
import math
3) !!! DON'T IMPORT INSIDE THE LOOP!!! Move import to the top.

math.log(c)
4) You must assign the result of math.log() to something:
c = math.log(c) [maybe]

5) Don't do this
d=log10(c)("print %log10(c)==%d")%(c,d)

Get all your results first then use print to convert floating point to the screen
print "result1 = %.4f, result2 = %.4f" %(c,d)
Here ".4" means only print 4 places to the right of the decimal.

5) while should take care of this
if c <=0:
print"error"

6) I don't see integer1 ever getting assigned
total=2*integer1*d

7) No value printed
print"total"


print "total = %.4f" %total [may be %d]
Sep 19 '06 #2
i try this:

integer1=raw_input("masukkan nombor pertama")
integer1=int(integer1)

while c>=1:
import math

c=float(raw_input("enter a value for c:"))
c=math.log(c)

while c<=0:
print"error"

total=integer1+math.log(c)

but doesn't work. it state there

Traceback (most recent call last):
File "C:/Documents and Settings/User/Desktop/000.py", line 4, in -toplevel-
while c>=1:
NameError: name 'c' is not defined
Sep 20 '06 #3
kudos
127 Expert 100+
Do you want to do something like this?

Expand|Select|Wrap|Line Numbers
  1. import math
  2.  
  3. integer1=raw_input("insert the first value\n")
  4. integer1= int(integer1)
  5.  
  6. c=raw_input (" enter a value for c:\n")
  7. c=int(c)
  8.  
  9. while c>=1:
  10.  c=math.log10(c)
  11.  
  12.  if c <=0:
  13.   print"error"
  14.  
  15. total=2*integer1*c
  16.  
  17. print total
??

but is this the least square method?

i try this:

integer1=raw_input("masukkan nombor pertama")
integer1=int(integer1)

while c>=1:
import math

c=float(raw_input("enter a value for c:"))
c=math.log(c)

while c<=0:
print"error"

total=integer1+math.log(c)

but doesn't work. it state there

Traceback (most recent call last):
File "C:/Documents and Settings/User/Desktop/000.py", line 4, in -toplevel-
while c>=1:
NameError: name 'c' is not defined
Sep 20 '06 #4
This is the program i try

import math

integer1=raw_input("insert the first value\n")
integer1= int(integer1)

c=raw_input (" enter a value for c:\n")
c=int(c)

if c>=1:
c=math.log10(c)

else:
print"error"


total=2*integer1*c

print total


when i run it, i get this


IDLE 1.2
>>> ================================ RESTART ================================
>>>
insert the first value
1
enter a value for c:
10
2.0
>>>


What should i do so that

i) it will show me the value of log10(c) first before it gives me the total(2kLog10(c))

ii) it will pritn there "log10(c)equals to".after we key in the value for c?

thank you.
Sep 20 '06 #5
bartonc
6,596 Expert 4TB
import math

integer1 = int(raw_input("insert the first value: "))

c = int(raw_input (" enter a value for c: "))

if c>=1:
log10ofc = math.log10(c)
print "log10(%d) = %f" %(c, log10ofc)

else:
print "error"


total = 2 * integer1 * c

print "total = %f" %total
Sep 21 '06 #6
Thank you for your help. settle dy...
Sep 21 '06 #7
when we ask user to key in thei data, we usually do this:

print"Insert value A:\n"
a1=raw_input("insert a1:\t")
a1=float(a1)
a2=raw_input("inset a2:\t")
a2=float(a2)

By doing this , we actually limited the data that they can key in.

If i wish to do it this way:

-I will first ask the user to key in the total number of data that they have(Lets 99), then user will be allow to key in 99 datas

What should i do
Sep 22 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Nalpo | last post: by
7 posts views Thread by ashkaan57 | last post: by
32 posts views Thread by priyam.trivedi | last post: by
4 posts views Thread by sathyashrayan | last post: by
1 post views Thread by Uwe Kotyczka | last post: by
6 posts views Thread by Blue sky | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.