Python Forum

Full Version: Changing User Input Strings Into Set Integer Values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. Im having a bit of trouble. Imtrying to get it so the user can input pi, and my program converts it to the math.pi module. However, I want the user to also be able to input integer values and have those print as well. My overall goal is to get the user to be able to type in two numbers and have them add, but i also want them to be able to type something like and pi, and have the program do 5 + 3.14159....
Heres what I got so far...
import math
yes = ["yes", "y", ""]
rst = ("yes")
while rst in yes:
    pi = math.pi
    x = (input("First Value: "))
    y = (input("Second Value: "))
    x = float(x)
    y = float(y)
    print(x + y)
    rst = str(input("Calculate another number? "))
    rst = rst.lower() #removes case sensitivity by making rst all lowercase
Use isdigit()
x=input("First Value: ")
if x.isdigit():
    x=int(x)
elif x=="pi":
    x=3.14159 
what are you expecting it to do (type in an "if it works right" example in output tags)? what does it actually do (copy and paste the output in output tags)? what do you see is wrong about that output? why does your code do nothing with the variable named pi? what do you want to do with the internal value of Pi, show 12 digits to the person running your code?
Well...im working on a calculator with my friend, and I eventully want to get it to the point were i can do fractions including pi. When you enter in sin, then it asks for a number to find the sin. I want then pi/3, as an example, be something I am able to input as a value...I can show the project so far, but it is about 300 lines of code, since our calculator includes many possible functions,