Python Forum
using a & for and - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: using a & for and (/thread-14779.html)



using a & for and - JunglinJay - Dec-17-2018

Welp, here goes!!

I'm very new to Python. Well, I'm new to programming in general. I work for a company that surveys buildings for future wireless infrastructure, and I wanted to build a program that would help my fellow co-workers to determine the type of WAP and mount they would use for installation. I decided to attempt to write a program that would ask simple questions and based off their answer, provide them with the package needed. Here is a quick example of what I have currently
value1 = input('Is the WAP going to be used Indoor or Outdoor? ')
print ('okay, you chose '+value1)
value2 = input ('Now, will this be an Omni or Directional?')
print ('okay, you chose' +value2)
if value1 == Indoor & value2 == Omni:
    print ('Test worked')
I get an error that says "Indoor not defined" and I'm a little confused because I assumed line 5 defines value1 as Indoor. Theres a lot more to this program, but if I can figure out how to use stored variables, it will at least get me started. I've spent hours researching videos and I cannot seem to find the right answer.


RE: Probably a dumb question - Gribouillis - Dec-17-2018

Use if value1 == "Indoor" and value2 == "Omni".


RE: Probably a dumb question - buran - Dec-17-2018

(Dec-17-2018, 06:34 AM)JunglinJay Wrote: I assumed line 5 defines value1 as Indoor
Griboullis provide solution, but I like to make a note about above statement.

on line 5 you use comparison operator == i.e. compare the current value of value1 to "Indooor" (here I stick to correct syntax). Same for value2. Because you use Indoor and Omni without quotes, python thinks these are variable names, not str literals.
On line 1 and line 3 you use assignment operator =. I.e. the value of value1 is assigned on line 1 and the value of value2 - on line 3. i.e. this is where these names are defined for first time.

By the way, the soon you start to use descriptive names, the better. e.g. value1 and value2 doesn't say much what these are. Consider for example wap_usage and mount_type.


RE: using a & for and - JunglinJay - Dec-17-2018

Griboullis, thank you! I will be sure to post my entire code next time. Buran, thank you and I changed my variables to a more descriptive name.