Having trouble with python simple code running in console [closed]

2024/7/7 7:08:54

I ran this code.Then it displayed the follwing in the console.

Traceback (most recent call last): File "", line 13, in NameError: name 'r' is not defined

import mathp = int(raw_input("Please enter deposit amount: \n"))
i = int(raw_input("Please input interest rate: \n"))
t = int(raw_input("Please insert number of years of the invesment: \n"))
interest = raw_input("Do you want a simple or compound interest ? \n")A = p(1+r*t)
B = p(1+r)^tif interest == "simple":print int(float(A))
elif interest == "compound":print int(float(B))
Answer

There were multiple errors and indentation problem ;I commented them where you made mistakes:

p = int(raw_input("Please enter deposit amount: \n"))
r = int(raw_input("Please input interest rate: \n")) #rename i to r
t = int(raw_input("Please insert number of years of the investment: \n"))
interest = raw_input("Do you want a simple or compound interest ? \n")A = p*(1+r*t) #multiply p with ()
B = p*(1+r)**t #same as B#** is powerif interest == "simple":print (float(A)) # you dont need to cast the float again to int
else: #since there is no other conditions it's obvious to print compound print(float(B))# you dont need to cast the float again to int
https://en.xdnf.cn/q/120227.html

Related Q&A

.upper not working in python

I currently have this codenum_lines = int(input()) lines = [] tempy = ctr = 1 abc = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z } for i in range(0, num_lines):tempy = input()lines.append([])l…

Python SKlearn fit method not working

Im working on a project using Python(3.6) and Sklearn.I have done classifications but when I try to apply it for reshaping in order to use it with fit method of sklearn it returns an error. Heres what …

extracting n grams from huge text

For example we have following text:"Spark is a framework for writing fast, distributed programs. Sparksolves similar problems as Hadoop MapReduce does but with a fastin-memory approach and a clean…

Python: Input validate with string length

Ok so i need to ensure that a phone number length is correct. I came up with this but get a syntax error.phone = int(input("Please enter the customers Phone Number.")) if len(str(phone)) == 1…

Mergesort Python implementation

I have seen a lot of mergesort Python implementation and I came up with the following code. The general logic is working fine, but it is not returning the right results. How can I fix it? Code: def me…

Use variable in different class [duplicate]

This question already has answers here:How to access variables from different classes in tkinter?(2 answers)Closed 7 years ago.I am a beginner in python. I have a problem with using variable in differ…

Embedded function returns None

My function returns None. I have checked to make sure all the operations are correct, and that I have a return statement for each function.def parameter_function(principal, annual_interest_rate, durati…

calculate days between several dates in python

I have a file with a thousand lines. Theres 12 different dates in a single row. Im looking for two conditions. First: It should analyze row by row. For every row, it should check only for the dates bet…

Appeding different list values to dictionary in python

I have three lists containing different pattern of values. This should append specific values only inside a single dictionary based on some if condition.I have tried the following way to do so but i go…

Split only part of list in python

I have a list[Paris, 458 boulevard Saint-Germain, Marseille, 29 rue Camille Desmoulins, Marseille, 1 chemin des Aubagnens]i want split after keyword "boulevard, rue, chemin" like in output[Sa…