0
My code just stopped running it and even my teacher cant find a mistake.
I have been doing this code for school and ive ran it multiple times and solved every syntax error and undefined things. Its about calculating compound interest and the code runs till " Masukkan bilangan tahun yang dilaburkan" and it wont calculate the compound interest or the simple interest. Why does it stop? Nama = str(input(" Masukkan Nama: ")) P = int(input(" Masukkan Principal: ")) r = float(input(" Masukkan peratus faedah: ")) t = float(input(" Masukkan bilangan tahun yang dilaburkan: ")) n = int(input(t/12)) simple_interest = (P*r*t) Compound_interest= (P*(1+r/n)**(n)**(t)) print = (simple_interest) print = (Compound_interest)
20 Antworten
+ 6
mhm i guess you use python3 for this the print function is called by:
print("some text")
if you use python 2 the function call should be
print "some text"
And may you need to change your instructor/teacher... this is a issue that everybody with a bit knowlegde of python instantly get notice....
anyways
keep working dude
happy coding =D
+ 16
I think don't change your code, change your teacher first 😅
+ 6
print = ( ) here may be you are using previous version syntax. it is just assignment statement. Remove = and use just like ex:
print( simple_interest)
print( compound_interest )
+ 5
https://code.sololearn.com/c04f35I2BQou/?ref=app
I think you are kidding . It is a simple code
+ 4
even my teacher cant find a mistake
LOL
+ 4
You're missing a closing parentheses `)` at the end of the compound interest formula line. Please look at my code solution carefully.
+ 3
Mozzy It worked! Thank you so much, and i will be sure to be less careless next time.
+ 2
This is my solution, found it to work correctly with the sample input values below. A few issues:
1. In the line assigning `Principal`, the type conversion should be float, not int, so that it can accept any currency value. E.g. 500.00
2. In the line assigning `n`, the input argument should be a meaningful message prompting a value to be entered, not just the number `t/12`. I assume `n` is the "number of times interest compounded per year", based on the compound interest formula. So either set it to 12 for monthly interest or get a value from the user.
3. The formula you used to calculate Compound_interest has one mistake. It should be **(n*t), not **(n)**(t). The latter is a power of a power.
4. The print statements, as others have already pointed out.
Sample input:
Abcd
500.0
0.03
7
12
Output:
simple_interest=105.0
Compund_interest=616.677400...
https://code.sololearn.com/cbt3vr5G2sVb/?ref=app
+ 1
avoid the use of = in print
+ 1
Jayakrishna🇮🇳 I have changed my code but unfortunately it still displayed the same as it did before.
+ 1
Can you share code link by saving it in playground..?
What is the error you getting?
+ 1
this is python right?
python has a function "print".
when you use '=', you just create a new variable named 'print'.
Normally this should generate a error because 'print' is a name of a python function.
If you just try to print simple_interest and Compound_interest you need do this:
print(simple_interest)
print(Compound_interest)
+ 1
Joseph Kamau Jayakrishna🇮🇳 the error i keep getting is
Masukkan Nama: Absarina
Masukkan Principal: 500
Masukkan peratus faedah: 0.03
Masukkan bilangan tahun yang dilaburkan: 7
>
^The code just displays that arrow and not the simple and compond interest, no number pops up.
@ Oma falk made this, im not sure if its a playground. Mind you, that im new to this and im using a python online complier called Programiz on my phone and cant seem to share it.
https://code.sololearn.com/c04f35I2BQou/?ref=app
+ 1
Looks like it is solved. Add related tags like "python", "SI","PTR".. that helps in search.
Note : you may already got it, just saying :
print = (simple_interest) is assignment, overrides print function.
print( simple_interest ) is output statement.
input() accept input as string form so there is no need to convert string again.
x = input() is enough, it's same as
x = str( input() ) so no need str cast.
0
can you share the code link
0
try the use of numbers
0
Oma Falk i assure you, i am not kidding as i still didnt get the output i was looking for. It could be me using a phone instead of a computer or that i wrote something in the code wrong but it only displays:
Masukkan Nama: absa
Masukkan Principal: 500
Masukkan peratus faedah: 0.07
Masukkan bilangan tahun yang dilaburkan: 3
>
Or
Masukkan Nama: absa
Masukkan Principal: 500
Masukkan peratus faedah: 0.07
Masukkan bilangan tahun yang dilaburkan: 3
O.25
Which is infact NOT the answer.
0
Mozzy After all of the new corrections..
Nama = str(input(" Masukkan Nama: "))
P = float(input(" Masukkan Principal: "))
r = float(input(" Masukkan peratus faedah: "))
t = float(input(" Masukkan bilangan tahun yang dilaburkan: "))
n = float(input(" Masukkan bilangan faedah compounded setiap tahun "))
simple_interest = (P*r*t)
Compound_interest= (P*(1+r/n)**(n*t)
print ( simple_interest )
print (Compound_interest)
and this is what my shell says:
File "<string>", line 10
print (simple_interest)
^
SyntaxError: invalid syntax
>
0
Hi
0
Hmm ..., Maybe in masukkan principal Will not juts 500 but it is 500.00, cause it was in float not integer?