Lesson goal: Asking questions: true or false (with variables)

Previous: Introduction | Home | Next: Compound true/false questions

In the last lesson, you saw how to directly compare two numbers, and see if a comparison was true or false.

In this lesson, we'll further explore this comparison, but instead of literal numbers, see how variables and even full mathematical expressions can be included in comparison questions---all with true or false answers.

Now you try. Using print, try displaying the true or false answers to the bullet-list questions, using the pre-defined variables in the code.

Type your code here:


See your results here:

This code will generally not run, as there is nothing inside of the ( and ) of the print statement. Try displaying the result of the following comparisons (using the variables a,b,c,d and x) using the print statement:
  • Is $\pi^2$ < 10?$ (hint: print(math.pi^2 < 10))
  • Is $b^2>b$?
  • Is $\pi^2 > a$?
  • Is $a+b == b+a$?
  • Is $b-a > 0$?
  • Is $a-a=0$?
  • Is $ab+0 == ab$?
  • Is $1*a == a$?
  • Is $0+a==a$?
  • Is $(a+b)(a-b)==a^2-b^2$?
  • Is $(a+b)(a+b)==a^2+2ab+b^2$?
  • If $a>c$ and $c>d$ then is $a>d$ (use 3 print statements for this one)?
  • If $a>b$ then is $1/a>1/b$?
  • Is $e^x>1+x$ for any value of $x$? (Hint: $e^x$ is math.exp(x) in computer programming).
  • Is $x^x\ge\left(\frac{1}{e}\right)^\frac{1}{e}$ for any value of $x$?
  • Is $a^a+b^a\ge a^b+b^a$?
  • Is $(1+x)^r\ge 1+rx$ (for any number $r$)?
Hint: Don't forget that computers don't know how to multiple automatically. So, something like $2ab$ has to be programmed in as 2*a*b. Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.