1. How many times the loop below will be executed? What is the value of variable counter after the loop?
counter = 1
while counter < 7:
counter+=2
print(counter)
2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”.
3. Complete the python below that asks user to enter the measurement of three lengths in feet and inches as integer values and compute the total length in feet and inches. For example, the total length of 5 feet 7 inches, 3 feet 8 inches, and 2 feet 10 inches is 12 feet inch; and 5 feet 3 inches, 3 feet 2 inches, and 2 feet 6 inches is 10 feet 11 inches.
feet1 = int(input('Enter feet of length 1: '))
inches1 = int(input('Enter inches of length :'))
feet2 = int(input('Enter feet of length 2: '))
inches2 = int(input('Enter inches of length 2 :'))
feet3 = int(input('Enter feet of length 3: '))
inches3 = int(input('Enter inches of length 3 :'))
Question 1: counter = 1 while counter < 7: counter+=2 print(counter) Number of times the loop below will be executed is 3 Value of variable counter after the loop is 7 Question 2: if MyInt%2==0: print("It is an even number") else: print("It is an odd number") Question 3: feet1 = int(input('Enter feet of length 1: ')) inches1 = int(input('Enter inches of length :')) feet2 = int(input('Enter feet of length 2: ')) inches2 = int(input('Enter inches of length 2 :')) feet3 = int(input('Enter feet of length 3: ')) inches3 = int(input('Enter inches of length 3 :')) inches = inches1+inches2+inches3 feets = feet1 + feet2 + feet3 + (inches//12) inches = inches%12 print(feets,"feet and",inches,"inches")
Get Answers For Free
Most questions answered within 1 hours.