Python: Im making a simple calculator for class. Whats wrong with this code? [duplicate]

2024/11/16 22:00:36

My teacher requests me to make a calculator that can calculate a 15% tip on a submitted price. I followed an online tutorial for this python application. I made a simple addition, subtraction, multiplication, and division calculator for practice before I make what my teacher requires. In the YouTube video I followed the python application ran on his computer. I get a a "Invalid Syntax" error in the Python Shell. I'm using Python 3.3.0. Thank you.


print "Hello"
def calc():x = int (raw_input("Input first integer: "))y = (raw_input("Input second integer: "))type = str.lower(raw_input("(A)dd, (S)ubstract, (M)ultiply, (D)ivide"))if type != "a" and type != "s" and type != "m" and type != "d":print ("Sorry, the command you entered is not calid.")calc():else:if type =="a":print ("The result is '" + str(x+y) + "'")elif type == "s":print ("The result is '" + str(x-y) + "'")elif type =="m":print ("The result is '" + str(x*y) + "'")elif type == "d":print ("The result is '" + str(float(x)/float(y) + "'")if str.lower (raw_input ("Would you like to perform another calculation?") == "y"):calc();else:exit([0])
calc();
Answer

because y is string

y = int(raw_input("Input second integer: "))
https://en.xdnf.cn/q/120280.html

Related Q&A

FileNotFoundError Python Script

I am trying to run a python script, .py in the windows command prompt. I drag the script from my files into the command prompt window. I run it. Then, the script presents a prompt for me to enter the f…

Filtered product of lists without repetitions

I need an efficient solution to find all combinations without repetitions of a given lists. It has to work like this: l1 = [1, 2, 3] l2 = [3, 4, 5] combinations(l1, l2) = [(2, 4), (3, 4), (1, 5), (1, 4…

int object is not callable only appears randomly

Sometimes this code works just fine and runs through, but other times it throws the int object not callable error. I am not real sure as to why it is doing so.for ship in ships:vert_or_horz = randint(0…

scraping css values using scrapy framework

Is there a way to scrap css values while scraping using python scrapy framework or by using php scraping. any help will be appreaciated

Access dict via dict.key

I created a dict source = {livemode: False}. I thought its possible to access the livemode value via source.livemode. But it doesnt work. Is there a way to access it that way?As a not source[livemode]…

Function not returning anything

My viewdef login(request):c = {}c.update(csrf(request))return render_to_response(request, login.html, c)def auth_view(request):username = request.POST.get (username, )password = request.POST.get (passw…

My entry box always returns PY_VAR1 value!!though Im using the .get function

please take a look at my code, its really simple I need to take the value from the entry box and use it in my program and when pressing the add button I print it ,it keeps giving me this value PY_VAR1…

Arthimatic Quiz Not Accepting Correct Answers

I am attempting to make an arithmetic quiz, but have run into this issue: Even if I input the correct answer, it seems to ignore the correct answer code and go straight to the incorrect answer code. Ba…

Linux - Check if python script is running in screen and run if not [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 1…

Making Phonebook in python : i want to get this screen by fixing my current code

I made my code like below....But as i input the data such as spam & number, previous data is deleted.So id like to make multiple value in one key... (i think using list is kinda good method)For exa…