If Statements

If statements are great when taking user input because you can answer different responses to your question. If statements are kind of difficult because of the indentations and small formatting issues, but if you are using Pycharm that is taken care of for you.

  • The first thing you have to do is open your previous code from taking user input. Which looks like this:
  • Once you have done that you have to create a question that there could be different answers to for example How are you doing? To do this you have to write another input question. And we add + name to add a personal aspect
  • Now instead of printing our response, you will use the if and else statement. You have to tell the computer to check the variable so write if the variable question is equal to good then print that’s great. We have to do a double equal sign because if we don’t python will think we are creating a variable.
  • There is a lot more you can do to build on this. For example, you can do two if statements right after each other in case they say good or decent.
  • That’s it now you can interact with your user. GREAT JOB!!

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

cheetahlion2018


0
Would love your thoughts, please comment.x
()
x