Problem 1
Collect an integer number from the user. (Be sure to convert it from a string to an mt, so that you store it in your variable as an mt! Tell
the user if their number is positive or not. Example output:
Give me an integer, I’ll tell you if it’s positive or not:—4
the nuinbeL —4 is negaUve ¡
Problem2
0k no biggie, nice work! You figured out how to tell if a number is positive or not. It was all about figuring out which comparison to
make, how to interpret an outcome of true for the comparison, and how to interpret an outcome of false. Do you know what the most
important part of what you did was? It wasn’t writing the code, it was stopping to think about 1) which scenarios should we have code
for, and 2) how do we distinguish which scenario we’re ¡n during runtime. Sometimes that second part can be tricky. We need to use
our tools to gather values we want to compare, and then we need to think about how to compare them. Can you do this with a problem
that asks you to use a “fancier1’ tool? Do you remember your “fancy” tools from when we talked about math and equations? Let’s find
out. Collect another integer from the user, and this time tell them if their number is even or odd. (Don’t panic here. What does it mean
to be an even number? What does it mean to be an odd number? Think about all the little tools we’ve played with. There’s gotta be one
that can tell me something useful about my number along these lines. At least give me a value that I can compare against something
else? Think it through. Sample output below:
Give me an integer, I’ll tell you if it’s even or odd:3
the number 3 is odd!
Get Free Quote!
315 Experts Online