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.
7 4561
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]
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
Do you want to do something like this?  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)


while c>=1:

c=math.log10(c)


if c <=0:

print"error"


total=2*integer1*c


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
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.
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
Thank you for your help. settle dy...
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...

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"...

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"...

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

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

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

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

by: WanHongbin 
last post by:
#include <stdio.h>
double square(); /*without declare
main()
{
double s;
s = square(2);
printf("%g\n", s);
}

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;

by: Charles Arthur 
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone

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

by: nemocccc 
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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 columnwise with in the specific length.
suppose the i have to...

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

by: Oralloy 
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bitfields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...

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, ZWave, WiFi, Bluetooth, etc. Each...

by: agi2029 
last post by:
Let's talk about the concept of autonomous AI software engineers and nocode agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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