Python Forum
Mixed string,Integer input variable issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mixed string,Integer input variable issue
#3
Other option is to make a dictionary,can just use your code and add dict().
Also showing f-string so can avoid code like "line_" + str(line).
# Make dictionary
line_record = dict(
    Line_1 = "Choice_C",
    Line_2 = "Choice_B",
    Line_3 = "Choice_A",
    )

line = input("pick a line number: ")
result = line_record.get(line, 'No record of that input')
print(result)
print('--------------')
# Example of f-string
print(f'Input was <{line}> with result of <{result}>')
Output:
λ python line_code.py pick a line number: Line_2 Choice_B -------------- Input was <Line_2> with result of <Choice_B> λ python line_code.py pick a line number: Line1000 No record of that input -------------- Input was <Line1000> with result of <No record of that input>
Reply


Messages In This Thread
RE: Mixed string,Integer input variable issue - by snippsat - Nov-06-2018, 09:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Commas issue in variable ddahlman 6 2,001 Apr-05-2024, 03:45 PM
Last Post: deanhystad
  Using string input for boolean tronic72 3 2,251 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 2,946 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  Replacing String Variable with a new String Name kevv11 2 1,800 Jul-29-2023, 12:03 PM
Last Post: snippsat
  input variable choice MCL169 7 2,566 Feb-19-2023, 09:00 PM
Last Post: MCL169
  Need help on how to include single quotes on data of variable string hani_hms 5 7,886 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 7,385 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 1,608 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 11,160 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 3,095 Jul-27-2022, 02:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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