Question: To evaluate expressions based on the precedence. To practice with conditional execution ( if / else statement ) . To practice with for loop Instructions:

To evaluate expressions based on the precedence.
To practice with conditional execution (if/else statement).
To practice with for loop
Instructions:
Write Python code to read an integer from the user; then print even if that number is an even number or odd otherwise..
The following code contains a logic error. Examine the code and describe a case in which the code would print something that is untrue
about the number that was entered. Explain why. Then correct the logic error in the code.
number = int(input("Type a number: "))
if number %2==0 :
if number %3==0 :
print ("Divisible by 6.")
else:
print("Odd.")
Factor out redundant code from the following example by moving it out of the if/else statement, preserving the same output.
ifx30:
a=2
x+=1
print("Python is awesome!", x)
else:
a=2
print(Pythonisawesome!,x)
The following code is poorly structured. Rewrite it so that it has a better structure and avoids redundancy. To simplify things, you may
assume that the user always types 1 or 2.(How would the code need to be modified to handle any number that the user might type?)
sum =1000
times = int(input("Is your money multiplied 1 or 2 times?"))
if times ==1:
donation = int(input("And how much are you contributing? "))
sum = sum + donation
count1+=1
total = total + donation
if times ==2:
donation = int(input("And how much are you contributing? "))
sum = sum +2* donation
count2+=1
total = total + donation
To evaluate expressions based on the precedence.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!