CMSC 201

Lab 3: Simple Logic Programming

Remember, before running each program type:

scl enable python33 bash

Programs

Temperature Suggestions

To practice using if statements, we are going to make a program where the user enters a number to symbolize the temperature and you print out a suggestion for them.

Ask the user to input the temperature and store it to a variable. Don't forget to cast it to an int!

Using if statements, check the value of the input and print these sentences to the screen:

  1. If the number is less than 25, print: "It's freezing outside."
  2. If the number is between 25 and 49, print: "It's a bit chilly, remember to bundle up."
  3. If the number is between 50 and 79, print: "The weather is wonderful!"
  4. If the number is between 80 and 100, print: "It's pretty hot outside."
  5. Otherwise, print: "It is way too hot."

With input 10, the output should looks something like this:

It's freezing outside.

Pets

Now we need to practice comparing strings. We are going to get an input from the user. If the input is "dog" or "cat" exactly, we want to tell the user that it is a pet.

You will need a variable to get input from the user once again asking what kind of animal they are asking about, no casting necessary this time.

Using if statements, check if the input says "dog" or "cat" in lowercase. Hint, remember how we talked about the words "and" and "or" in if statements?:

  1. If the input is "dog" or "cat" print: "This is a pet."
  2. Otherwise, print: "This is not a pet."

With input "frog", the output should looks something like this:

This is not a pet.