Problem 1
Write a program that reads an integer and prints whether it is negative, zero, or positive.
Problem 2
Write a program that reads a floating-point number and prints "zero" if the number is zero. Otherwise, print "positive" or "negative". Add " small" if the absolute value of the number is less than 1, or "large" if it exceeds \(1,000,000\).
Problem 2
Explain the difference berween $$ \begin{aligned} &s=0 \\ &\text { if } x>0: \\ &s=s+1 \\ &\text { if } y>0: \\ &s=5+1 \end{aligned} $$ and $$ \begin{aligned} &s=0 \\ &\text { if } x>0 \text { : } \\ &s=5+1 \\ &\text { elif } y>0= \\ &s=5+1 \end{aligned} $$
Problem 3
Find the errors in the following if statements. a. if \(x>0\) then print \((x)\) b. If \(1+x>x\) as \(\operatorname{serct}(2):\) \(y=y+x\) c. if \(x=1:\) \(y+=1\) d. XStr = input("Enter an integer value") \(x=\operatorname{int}(x S t r)\) if \(x\) Str. isdigito : sum \(=\) sum \(+x\) else : print("Bad input for \(\left.x^{*}\right)\) e. TetterCrade = "F" if grade \(>=90\) : letterGrade \(={ }^{3} \mathbf{A}^{*}\) if grade \(>=80:\) TetterGrade \(={ }^{3} \mathrm{~B}^{*}\) if grade \(x=70\); lettercrade = "C" if grade \(>-60:\) letterGrade = "d"
Problem 3
Write a program that reads an integer and prints how many digits the number has, by checking whether the number is \(\geq 10, \geq 100\), and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it by \(-1\).
Problem 4
Write a program that reads three numbers and prints "all the same" if they are all the same, "all different" if they are all different, and "ncither" otherwise.
Problem 4
$$ \begin{aligned} &\text { What do these code fragments print? }\\\ &\text { a. } \begin{aligned} n &=1 \\ m &=-1 \\ \text { if } n &<-m: \\ \text { print }(n) & \\ \text { else : } & \\ & \text { print (n) } \end{aligned} \end{aligned} $$
Problem 5
Write a program that reads three numbers and prints "increasing" if they are in increasing order, "decreasing" if they are in decreasing order, and "ncither" otherwise. Here, "increasing" means "strictly increasing", with each value larger than its predecessor. The sequence 344 would not be considered increasing.
Problem 5
Suppose \(x\) and \(y\) are variables each of which contains a number. Write a code fragment that sets \(y\) to \(x\) if \(x\) is positive and to 0 otherwise.
Problem 6
Suppose \(x\) and y are variables each of which contains a number. Write a code fragment that sets y to the absolute value of \(x\) without calling the abs function. Use an if statement.