Conditional and Booleans

Attention: Our videos have subtitles in all partner languages. You can switch on subtitles in the youtube player by clicking the gear wheel and selecting your preferred language.

In this section, we delve deeper into program logic and introduce the conditionals that help you control which part of your code is run at a given time. We also explain the logic of booleans and how to use them. What if you could make your programs make choices? That is exactly what this video is all about. You will learn how to give an output based on the input. If the input is true the program does something, if it is false, it will do something else.

Sending Greetings
1) Declare a string name and add user input to it. Ask the user for a name. 2) Print "Hello, " and the name that has been entered by the user.
Solution
 name = input("Please enter a name") # Ask for user input

print("Hello, " + name) # Say hello to the user
Ask for the age
1) Declare a variable age and ask the user for a number input. 2) Declare a second variable sentence and assign the values "Your age is: " and the value that has been entered by the user 3) print the sentence
Solution
 age = int(input("Please enter your age")) # Here we convert the input to a number

sentence = "Your age is: " + age

print(sentence)