-1

How do I ask the user to input how far away someone is?

e.g.

"How far away is the closest person: "

and then get it to tell me if it is under 600m

e.g.

"Canon start Rocket Lift Off because the closest person is less than 600m away
jscs
  • 63,694
  • 13
  • 151
  • 195
M.Cousins
  • 15
  • 5
  • Did you try anything? Please [edit] your question and include the code you have tried. –  Mar 15 '16 at 06:47
  • Not a dupe of that question (related possibly). This question asks how to do input. The linked question asks how to use a specific function you *already know* the name of - and is python 2 specific. – Glen Davies Jun 25 '19 at 09:46

3 Answers3

2

Use Python's input() method.

>>> a = input("Input the distance: ")
Input the distance: 800
>>> print(a)
800

For the 600m requirement, read up on if statements.

>>> a = "test"
>>> if a == "test":
...     print("true")
...
true
Chuck
  • 866
  • 6
  • 17
1

To ask the user a question, do:

x = raw_input("How far away is the closest person: ")

for python 2.7 or

x = input("How far away is the closest person: ")

for python 3

and then as you will probably have worked out by now:

if x < 600:
    # do something
ml-moron
  • 888
  • 1
  • 11
  • 22
0

Just use print() to display information, input() to receive the input info, and if statement to determine whether the distance is enough. float(input()) means converting what you input to a float type object.

print "How far away is the closest person: "
if float(input()) <= 600:
    print "Canon start Rocket Lift Off because the closest person is less than 600m away"
Yunhe
  • 665
  • 5
  • 10