So, this was SUPPOSED to be a real attempt at a Calculator in Python3, but.....

B

blackneos940

Guest
It just doesn't seem to add up..... ... ... ... Heh.... :3 Anyway..... I run it, and it says this:

Traceback (most recent call last):
File "C:\Users\Adam\Documents\Testing_Grounds\Examples_of_Python\Smashing_Atoms\My_Programs\Serious_Stuff\Actual_Calculator.py", line 29, in <module>
print (number / number_2)
TypeError: unsupported operand type(s) for /: 'str' and 'str'

This happens when I try to do everything but Add.... And even THAT doesn't work like I THINK it should..... :< It just takes your numbers and pieces them together....... :( 3 and 8 do NOT equal 38..... :< What happened.....? Will I always be this way......? Oh yeah..... :) Here's the Code, before I forget..... :D

Code:
print ("My next attempt at a good Calculator in Python!!\n")

print ("Enter a number now!\n")

number = input()

print ("Enter the Math Operator to Calculate the numbers! (+, -, *, or /)\n")

math_symbol = input("")

print ("Enter a second number!\n")

number_2 = input()

if math_symbol == "+":

    print (number + number_2)

elif math_symbol == "-":

    print (number - number_2)

elif math_symbol == "*":

    print (number * number_2)

elif math_symbol == "/":

    print (number / number_2)

else:

    print ("Error: Please input one of the four Math Operators!")

..... Thanks for any help guys.... :)
 


In python 3 input() returns a string. You need to convert this string to a integer type.
Use int() function to convert to integer.
Code:
 number = int( input() )
Code:
number_2 = int( input() )
 
In python 3 input() returns a string. You need to convert this string to a integer type.
Use int() function to convert to integer.
Code:
 number = int( input() )
Code:
number_2 = int( input() )
Oh..... Whoops....... :oops: :confused: I forgot about that..... :D Thanks!..... :D
 
There are many things that one build in Python. This tutorial covers exhaustively about Python usage and talks on several topics.
- Python tutorial
 

Members online


Top