Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input variable choice
#1
I'm using simple ideas and theories to practice coding. I'm simply trying to except a input from user that returns a variable string. I want the user to choose a patch that will be developed as i go.
print(Welcome to The Bronx)
input('Will you fight for good or bad?: ') 

good = 'Police Academy'
bad = 'corner lookout'
input('good or bad: ')

if input == (good):
    print(good)
else:
    print(bad)
Yoriz write Feb-19-2023, 07:15 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Hi,

you need to bind the result of input() to a variable - otherwise the input just disappears.

Like:
name = input('What is your name?')
print(f'Hello {name}')
This is pretty basic stuff. Maybe you want to read through the corresponding section in the Python tutorial on docs.python.org to get a deeper understanding.

Regards, noisefloor
MCL169 likes this post
Reply
#3
As mentioned above read through the docs on input and variables.

An example would be

choose = input('Will you fight for good or bad?\n>> ').lower()
if choose == 'good':
    print('Good')
elif choose == 'bad':
    print('Bad')
else:
    print('That is not a valid option.')
MCL169 likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#4
print('Welcome to The Bronx')

choose = input('Will you fight for good or bad?: ')
good = "police academy"
bad = "corner lookout"
if choose == 'good':
print(good)
elif choose == 'bad':
print(bad)
else:
print('not an option')
Reply
#5
(Feb-19-2023, 07:01 PM)noisefloor Wrote: Hi,

you need to bind the result of input() to a variable - otherwise the input just disappears.

Like:
name = input('What is your name?')
print(f'Hello {name}')
I am basically engulfing myself in Python to change careers. You're right I'm getting a head of myself and need to focus on the basics. I'm on youtube and Udemy. Just starting out. Ill check the tutorial and documentation. Thank You...


This is pretty basic stuff. Maybe you want to read through the corresponding section in the Python tutorial on docs.python.org to get a deeper understanding.

Regards, noisefloor
Reply
#6
You are asking your user to enter "police academy" or "corner lookout". This would be quite difficult for your user because you provide no info about what is a valid answer. I think what you want to do is ask them to enter "good" or "bad", and print "police academy" or "corner lookout".
if input("Are you good or bad? ").lower() in ("good", "g"):
    print("Police Academy"
else:
    print("Corner Lookout")
Reply
#7
print('Welcome to The Bronx')

choose = input('Will you fight for good or bad?: ')
good = "police academy"
bad = "corner lookout"
if choose == 'good':
print(good)
elif choose == 'bad':
print(bad)
else:
print('not an option')

# binding worked
Reply
#8
(Feb-19-2023, 08:55 PM)deanhystad Wrote: You are asking your user to enter "police academy" or "corner lookout". This would be quite difficult for your user because you provide no info about what is a valid answer. I think what you want to do is ask them to enter "good" or "bad", and print "police academy" or "corner lookout".
if input("Are you good or bad? ").lower() in ("good", "g"):
    print("Police Academy"
else:
print("Corner Lookout")

I want them to choose good or bad
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,432 Sep-10-2023, 10:27 PM
Last Post: janeik
  How to include input as part of variable name Mark17 4 2,496 Oct-01-2021, 06:45 PM
Last Post: Mark17
  random.choice HELP samuelbachorik 4 2,262 Aug-18-2021, 03:24 PM
Last Post: naughtyCat
  ???: if "{choice}" in self._command BaiYouLing4 3 2,020 Aug-23-2020, 05:40 AM
Last Post: BaiYouLing4
  trying to input a variable using random.choice python63 9 3,609 Aug-13-2020, 05:37 PM
Last Post: python63
  Would like to input a date variable and determine whether it is within the time range harold 3 2,563 Jan-05-2019, 09:04 AM
Last Post: Gribouillis
  Mixed string,Integer input variable issue maderdash 2 2,747 Nov-06-2018, 09:46 AM
Last Post: snippsat
  Save User Input From LineEdit Box To Variable digitalmatic7 2 8,339 Nov-22-2017, 05:34 PM
Last Post: digitalmatic7
  input defines variable but it's not defined tozqo 5 7,251 Jun-05-2017, 02:45 AM
Last Post: tozqo
  Taking user input and storing that to a variable then storing that variable to a list jowalk 12 37,319 Mar-27-2017, 11:45 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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