Question

1. How many times the loop below will be executed? What is the value of variable...

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 :'))

Homework Answers

Answer #1
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")
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. The conditon of a "while" loop and a "for" loop are executed at the ____________...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________ of these loops. 2. What will the following code fragment print?    for (i = 0; i < 4; i++)        cout << i + 1; cout << i; 3. What is the result in answer below? int int1=16; int int2=5; int answer=0; answer = int1 / int2 + (5 * 2);
3.plese to write the correct code: The code below will loop as long as the number...
3.plese to write the correct code: The code below will loop as long as the number that you enter isn’t negative. It will add each non negative number to the current sum. It will print out the sum and average of all of the numbers you have entered. But someone jumbled up the code. Can you reorganize and indent it so it works properly? count = count + 1 message = "Enter an integer or a negative number to stop"...
How many times will the body of the loop be executed? var Total = 1; for...
How many times will the body of the loop be executed? var Total = 1; for (intIndex = 1; intIndex < 7 ; intIndex += 2) { Total += intIndex; }
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking...
Draw a flowchart based on the Python code below: ch = -1 #Variable declared for taking option entered by the user print("Enter 0 to 5 for following options: ") print("0-> Issue new ticket number.") print("1-> Assign first ticket in queue to counter 1.") print("2-> Assign first ticket in queue to counter 2.") print("3-> Assign first ticket in queue to counter 3.") print("4-> Assign first ticket in queue to counter 4.") print("5-> Quit Program.") tickets = [] #Declaring list to store...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
In python 3, how would you do the following? 1. conditional to check if choice is...
In python 3, how would you do the following? 1. conditional to check if choice is 7. if choice is 7, print out "lucky". if not, print "unlucky" 2. You're provided with a random number in a variable called num. Use a conditional to check if the number is odd. If num is odd, print "odd". If not, print "even" (use modulus % to figure out if number is odd)
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Complete the Python programming snippet given below based on the information provided here. a = int(input("Enter...
Complete the Python programming snippet given below based on the information provided here. a = int(input("Enter variable a:")) b = int(input("Enter variable b:")) print(a,b) a = a + b # enter your solution here # end of your code print(a,b) Two values are entered and stored into the variables a and b. The values of the variables are then switched so that the variable b now contains the original value of the variable a and the variable a now contains...
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT