Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using a & for and
#1
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.
Reply
#2
Use if value1 == "Indoor" and value2 == "Omni".
Reply
#3
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

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