Python Forum
Changing User Input Strings Into Set Integer Values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing User Input Strings Into Set Integer Values
#1
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
Reply
#2
Use isdigit()
x=input("First Value: ")
if x.isdigit():
    x=int(x)
elif x=="pi":
    x=3.14159 
Reply
#3
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,061 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  Trying to understand strings and lists of strings Konstantin23 2 761 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  restrict user input to numerical values MCL169 2 915 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,071 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,088 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,099 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,917 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,179 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,890 May-10-2022, 02:44 AM
Last Post: alisha17
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,485 Apr-05-2022, 06:18 AM
Last Post: C0D3R

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020