Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Taking user input
#1
Hi i am very new to python, and coding in general. I am a sheet metal apprentice, and am trying to do something to figure out the stretchout of a transition(i know you probably dont know what that means). Basically i want to get all the info from the user about the transition. I understand how to do input() to get the numbers that i need, but i need more than numbers. i need to take in alot of info. So one of the things i need to know is what side of the transition offsets(left or right side of transition). this is just one of the things i need, but basically i need to bring in the info, but i cant find out how to do this since it could either be left or right without having to print it using an if statement. i need to get all the info before the program does the math. so i cannot ask the question, and the use an if statement for left or right. I dont know if what i am trying to do is possible, but i want to try it for fun.




this is an example of what i am doing, and i can get about half the info i need because the numbers are easy to acquire. However i dont understand how to ask all the question i need because if i use an if statement then i have to print after i was the question.

###################User input needed###############################

height = float(input("What is the height of the transition? "))

bot_length = float(input("What is the length of transition\(bot of page\)? "))
bot_width = float(input("What is the width of transition\(bot of page\)? "))

top_length = float(input("What is the length of transition\(top of page\)? "))
top_width = float(input("What is the width of transition\(top of page\)? "))


########################Problem section##########################################

offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")

if offset_left_or_right=="left":
bot_left_up_to_left_or_right = input("Is bottom left going up to the left or right? ")
if bot_left_up_to_left_or_right=="left"

else:



#################################what i need###################################

offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")

if offset_left_or_right=="left":
bot_left_up_to_left_or_right = input("Is bottom left going up to the left or right? ")
if bot_left_up_to_left_or_right=="left"
""""SAVE(left = bot_left_up_to_left)""""

"""""bot_left_up_to_left"""""

that way i can use the answer and save it as a new variable that i can use in a math equation

perhaps it would be easier to do a gui to where all the info would be input, but i wouldnt know how to do a gui at all lol
Reply
#2
Please use Python tags when posting code. See the BBCode link in my signature below for instructions.

I'm not totally sure what the tree of questions is going to look like, but you might think about something like this:

offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")
query = "Is bottom {} going up to the left or right? "
bot_corner_to_left_or_right = input(query.format(offset_left_or_right))
This allows you to modify the question being asked, and store where the bottom corner is going, regardless of which corner it is.

We often have to tell new programmers to use more descriptive variable names. That's not a problem here, but I think you're over doing it. I seen guidelines saying that variable names start to be a problem when they are longer than 12 to 15 characters. Take offset_left_or_right. It seems you are just adding the possible values. Unless it needs to be clarified that it's not some other offset, I would just call it offset.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Sep-19-2018, 03:20 AM)ichabod801 Wrote: Please use Python tags when posting code. See the BBCode link in my signature below for instructions.

I'm not totally sure what the tree of questions is going to look like, but you might think about something like this:

offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")
query = "Is bottom {} going up to the left or right? "
bot_corner_to_left_or_right = input(query.format(offset_left_or_right))
This allows you to modify the question being asked, and store where the bottom corner is going, regardless of which corner it is.

We often have to tell new programmers to use more descriptive variable names. That's not a problem here, but I think you're over doing it. I seen guidelines saying that variable names start to be a problem when they are longer than 12 to 15 characters. Take offset_left_or_right. It seems you are just adding the possible values. Unless it needs to be clarified that it's not some other offset, I would just call it offset.



im sorry, but i dont actually see that edit button anymore or i would change it. However i have long names because i have to ask the offset, if it offsets left or right, top offset, and bot offset. If it offset on left side i have to ask if bottom left offsets up and to the left or right, and if it offsets on right i need to ask the same thing for the right. i would love for them to be shorter however i want to make sure i know what every tag is for. i quickly put this code in, and it looks like it should work.
[python]
offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")
query = "Is bottom {} going up to the left or right? "
bot_corner_to_left_or_right = input(query.format(offset_left_or_right))
[/python]
how would i take there second answer and save it as bot_corner_up_to_left or bot_corner_up_to_right depending on what they answer. so that i the equation would know that they typed in left and would save it as bot_corner_up_to_left. Sorry i dont want you to have to write it all for me, but i have been looking all night for some way to do it.
Reply
#4
Don't know exactly what you need, but perhaps you might consider a slightly different approach of showing a table of the various configurations, and letting the user pick the variation concerned. You can then do the inputs for that configuration.

(If you are outputting graphically rather than to a console, you could offer to pick from pictures rather than text.)
I am trying to help you, really, even if it doesn't always seem that way
Reply
#5
(Sep-19-2018, 03:42 AM)mtndewwarrior Wrote: how would i take there second answer and save it as bot_corner_up_to_left or bot_corner_up_to_right depending on what they answer. so that i the equation would know that they typed in left and would save it as bot_corner_up_to_left.

The equation knows that you typed in left because offset_left_or_right is equal to left. You store the information in bot_corner_to_left_or_right regardless of the answer to the first question. You use the combination of offset and bot_corner_to to tell what's going on.

Think about it this way. If offset is 'left', then bot_corner_up_to_left is 'left' or 'right', and bot_corner_up_to_right is undefined/empty. If offset is 'right', then bot_corner_up_to_left is undefined/empty and bot_corner_up_to_right is 'left' or 'right'. So you always have an empty variable. It simplifies your code to combine the two variables, and it never loses information. Then you can use the value of offset to determine the meaning of the bot_corner_to_left_or_right.

You can do it the way you are doing, but it's going to make your code a lot more complicated. Especially if I'm right that there is more to this equation than just what we're talking about. The more complicated your code is, the harder it is going to be to write and maintain. So you want to go for simpler code whenever you can.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
(Sep-19-2018, 08:14 AM)gruntfutuk Wrote: Don't know exactly what you need, but perhaps you might consider a slightly different approach of showing a table of the various configurations, and letting the user pick the variation concerned. You can then do the inputs for that configuration.

(If you are outputting graphically rather than to a console, you could offer to pick from pictures rather than text.)

I thought about a gui where the user could input the info, but i just need to practice more lol. I have been using python for about 1 day, and thought that doing something that i could use would be a good way to do it. I have made a simple version of what i am trying to do, but you have to enter all 4 sides separately and get the cut list for each side. I want people to enter all the info about the transition, and the program spits out the cut list for all 4 sides. So a gui might be the way to go, but we will see where it takes me kinda just having fun with it to help me learn python, and hopefully make something that people or atleast i can use.

offset_left_or_right = input("Which side of the transition is offset? Left or Right? ")
query = "Is bottom {} going up to the left or right? "
bot_corner_to_left_or_right = input(query.format(offset_left_or_right))
so with this code i can now bot_corner_to_left_or_right and the program will know that if they selected left or right, and i could now use bot_corner_to_left_or_right in another command and it will know what is the input?

Also yes there is a ton that this program will have to do. i lot of info with need to put input to figure which way the transition is offsetting which will all change how the entire cut list for the transition is figured out.

[Image: url?sa=i&rct=j&q=&esrc=s&source=imgres&c...9888061613]

so this is a transition a very basic picture, and the picture below is basically what i want to find

[Image: 133606.jpg]

The very basic way i can put this is that a transition is like a trapezoid, and each side can offset. So basically you want to find the true length(hypotenuse) of each side so you know how big of piece of metal you need to cut. in order to find the true length you have to know the offset of the side of the metal(rise) and the height of the transition(run). then you solve for the true length(hypotenuse). However with each side offsetting the program has to know which way each side is offset and the height of the fitting, and rather than ask about each individual side i want them to just input only the info that is needed for the program to figure out all the sides for the user. That is only part of it. When you find the true length that is only the height of the fitting. So you need to know the width of the stretchout that i was why i need to know if bot left corner is offsetting up to the right, what the top of the fitting is doing(offsetting up or down), how far the fitting is offsetting, and which way the arrow is pointing so i know if the top or bottom is what is offsetting up or down lol. There is a lot to do lol i expect this to take me a long time to figure out, but i figured it would be a great way to learn
Reply
#7
(Sep-20-2018, 12:35 AM)mtndewwarrior Wrote: so with this code i can now bot_corner_to_left_or_right and the program will know that if they selected left or right, and i could now use bot_corner_to_left_or_right in another command and it will know what is the input?

Yes. Whatever text they enter is stored in that variable. Note that user input can be tricky. They might enter 'left' or they might enter 'Left' or they might enter 'left ' (with a space at the end). Since these are not the exact same characters, they are not equal to each other. That's why you will often see:

direction = input('Left or right? ').strip().lower()
Input returns a string. Then the strip method of that string returns the string with no spaces at the start or end. Then the lower method of that string returns the string with all the letters lower cased.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
Thank you for all the help so far i will reply to the post with other questions if i have any others with inputting all of the info.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 991 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 869 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,025 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,033 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,030 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,837 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,827 May-10-2022, 02:44 AM
Last Post: alisha17
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,434 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Matplotlib - close multple plots with user input Positron79 0 1,698 Dec-01-2021, 05:26 PM
Last Post: Positron79

Forum Jump:

User Panel Messages

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