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)

25th Nov 2022, 2:47 PM
Ray Ramond
20 Réponses
+ 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
26th Nov 2022, 11:35 AM
S3R43o3
S3R43o3 - avatar
+ 16
I think don't change your code, change your teacher first 😅
26th Nov 2022, 10:05 AM
Amul Gaurav
Amul Gaurav - avatar
+ 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 )
25th Nov 2022, 2:51 PM
Jayakrishna 🇮🇳
+ 5
https://code.sololearn.com/c04f35I2BQou/?ref=app I think you are kidding . It is a simple code
25th Nov 2022, 6:35 PM
Oma Falk
Oma Falk - avatar
+ 4
even my teacher cant find a mistake LOL
25th Nov 2022, 2:57 PM
SoloProg
SoloProg - avatar
+ 4
You're missing a closing parentheses `)` at the end of the compound interest formula line. Please look at my code solution carefully.
26th Nov 2022, 6:58 AM
Mozzy
Mozzy - avatar
+ 3
Mozzy It worked! Thank you so much, and i will be sure to be less careless next time.
26th Nov 2022, 7:05 AM
Ray Ramond
+ 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
26th Nov 2022, 4:10 AM
Mozzy
Mozzy - avatar
+ 1
avoid the use of = in print
25th Nov 2022, 3:41 PM
Joseph Kamau
Joseph Kamau - avatar
+ 1
Jayakrishna🇮🇳 I have changed my code but unfortunately it still displayed the same as it did before.
25th Nov 2022, 4:11 PM
Ray Ramond
+ 1
Can you share code link by saving it in playground..? What is the error you getting?
25th Nov 2022, 4:40 PM
Jayakrishna 🇮🇳
+ 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)
25th Nov 2022, 6:39 PM
Giannis
Giannis - avatar
+ 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
26th Nov 2022, 2:51 AM
Ray Ramond
+ 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.
26th Nov 2022, 11:54 AM
Jayakrishna 🇮🇳
0
can you share the code link
25th Nov 2022, 4:17 PM
Joseph Kamau
Joseph Kamau - avatar
0
try the use of numbers
25th Nov 2022, 4:22 PM
Joseph Kamau
Joseph Kamau - avatar
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.
26th Nov 2022, 3:03 AM
Ray Ramond
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 >
26th Nov 2022, 6:20 AM
Ray Ramond
0
Hi
27th Nov 2022, 12:23 PM
Alireza Shahmirzaee
Alireza Shahmirzaee - avatar
0
Hmm ..., Maybe in masukkan principal Will not juts 500 but it is 500.00, cause it was in float not integer?
27th Nov 2022, 1:34 PM
Muh Kurniawan
Muh Kurniawan - avatar