473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 4561
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

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

Similar topics

1
by: Veverita | last post by:
Hi there I'm hoping that someone can help me with a question I have about javascript syntax. I got an html page that uploads an image and some text field to a database. What I'd like to do...
1
by: Nalpo | last post by:
Hi, i want to update several Textboxes by reading the value of another Box. For that i use the following small script: <form name="form1" method="POST"> <input type="text" name="xx" value ="1"...
7
by: ashkaan57 | last post by:
Hi, I was trying to display a small colored square using <table> tag. It worked fine on the screen but when I do print preview, the square shows up as white. I used both: <table width="15"...
32
by: priyam.trivedi | last post by:
Hi! Could anyone tell me how to find the square root of a number without using the sqrt function. I did it by using Newton's Formula. How can it be done by using the Binomial Theorem/Taylor...
4
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a...
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
1
by: Uwe Kotyczka | last post by:
Hallo, sorry for multiposting, but I am really looking for some hint to solve my problem. And no, I don't use Matlab, but maybe the matlab people have an idea nevertheless. I have to solve a...
5
by: WanHongbin | last post by:
#include <stdio.h> double square(); /*without declare main() { double s; s = square(2); printf("%g\n", s); }
6
by: Blue sky | last post by:
Hi ,I think the follow program is right in logical But why the compiler output :"square:declared identifier" #include<stdio.h> #include<math.h> int main() { double x1;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.