Python Forum
Help with my first program - 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: Help with my first program (/thread-2141.html)



Help with my first program - CadWizard - Feb-21-2017

Hi everybody, I have just started learning Python and have just jumped straight in and given it a go as thats what most people recommend.

At work (Underfloor heating design) we have to 2 design teams "Runners" and "Repeaters" and each team handles different projects, I would like to create a small program that can aid anybody not in the design department to see which of the 2 design teams will design the project. 

I would like the program to ask a series of questions to determine which team it goes to, the program does work to some degree however when it comes to a conclusion the program just terminates and doesn't give the user anytime to read the result. Also I dont think the way I have used If and Else is correct and there is probably a much more efficient way of doing it all. 

Sorry for the long post but please find my code below, any help would be greatly appreciated. 
          
#The NS record is basically the customer account number
NSname = input("Please enter the NS Record ")


HP = input ("Is the project using a Nu-Heat Heat Pump?, Yes or No ")

if HP == 'Yes':

   print ("This is a Repeater project")

   if HP == 'Yes':

       raise SystemExit    

     

Size = input ("Is the project over 200 SQM? ")

if Size == 'Yes':

   print ("This is a Repeater project")

   if Size == 'Yes':

       raise SystemExit  



LPM = input ("Is this project over 120 SQM of Lo-Pro Max? ")

if LPM == 'Yes':

   print ("This is a Repeater project")

   if LPM == 'Yes':

       raise SystemExit


LP = input ("Is this project over 60 SQM of Lo-Pro10? ")

if LP == 'Yes':

   print ("This is a Repeater project")

   if LPM == 'Yes':

       raise SystemExit


else:

   print ("This is a runner")



RE: Help with my first program - wavic - Feb-21-2017

What is printed should be on the screen/terminal to read it. 

Once you check for an answer don't need to do it again in the same if block.

if HP == 'Yes':
 
   print ("This is a Repeater project")
   raise SystemExit
You can use str.lower() to convert the answer to lowercase and check for 'yes'. The way how it is right now if one enter 'yes' instead of 'Yes' the if condition will be False.

if HP.lower() == 'yes':


RE: Help with my first program - ichabod801 - Feb-21-2017

I think raising SystemExit is a bit excessive. It's like a shotgun when you just want to turn of the light switch.

Looking at your program, you keep asking questions, a yes meaning it's a repeater, and if they're all no it's a runner. When you do something over and over again, you should try a loop:

questions = ['Do you like spam? ', 'Do you like dead parrots? ', 'Do you like the Spanish Inquisition? ']
fan = 'not a Monty Python fan.'
for question in questions:
    answer = input(question):
    if answer.lower() == 'yes':
        fan = 'a Monty Python fan.'
        break
print('You are', fan)
The above program asks a bunch of questions. If you answer yes to any of them, it says you are a Monty Python fan. If you answer no to any of them, it says you are not a Monty Python fan. Using break within a loop is like turning off the light switch (it skips out of the loop, without shutting everything down).


RE: Help with my first program - CadWizard - Feb-22-2017

Thanks very much wavic and ichabod801, I will have another go and let you know how I get on.