Question

Summary In this lab the completed program should print the numbers 0 through 10, along with...

Summary

In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop.

Instructions

  1. Write a for loop that uses the loop control variable to take on the values 0 through 10.
  2. In the body of the loop, multiply the value of the loop control variable by 2 and by 10.
  3. Execute the program and verify that the output is correct

-----

# NewMultiply.py - This program prints the numbers 0 through 10 along

# with these values multiplied by 2 and by 10.

# Input:  None

# Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10.

#Initialized the variables

head1 = "Number: "

head2 = "Multiplied by 2: "

head3 = "Multiplied by 10: "

# Constant used to control loop

NUM_LOOP_START = 0

# Constant used to control loop

NUM_LOOP_END = 10

#Prompt the output statement

print("0 through 10 multiplied by 2 and by 10.")

print(head1,"\t", head2, "\t", head3)

#Initialized the variables

numberCounter = 0

byTen = 10

byTwo = 2

NUM_LOOPS = 10

#for loop that uses the loop control variable

#to take on the values 0 through 10 along

#with their values multiplied by 2 and by 10

for numberCounter in range(NUM_LOOPS+1):

    print(numberCounter,"\t\t\t", numberCounter*byTwo, "\t\t\t",numberCounter*byTen)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
head1 = "Number: "
head2 = "Multiplied by 2: "
head3 = "Multiplied by 10: "
NUM_LOOPS = 10

print("0 through 10 multiplied by 2 and by 10" + "\n")

for i in range(NUM_LOOPS + 1):
    print(head1 + str(i))
    print(head2 + str(i * 2))
    print(head3 + str(i * 10))
Add a comment
Know the answer?
Add Answer to:
Summary In this lab the completed program should print the numbers 0 through 10, along with...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone help me with this Python code Summary In this lab, you work with the...

    Can someone help me with this Python code Summary In this lab, you work with the same Python program you worked with in Labs 5-1 and 5-3. As in those earlier labs, the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. However, in this lab you should accomplish this using a while loop with a break statement. Instructions Make sure that the file NewestMultiply.py is selected and open. Write...

  • Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these...

    Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these values multiplied by 2 and by 10. // Input: None. // Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10. public class NewMultiply {    public static void main(String args[])    {               String head1 = "Number: ";        String head2 = "Multiplied by 2: ";        String head3 = "Multiplied...

  • Java Submit a program in a .java file. The program should print a multiplication table for...

    Java Submit a program in a .java file. The program should print a multiplication table for the numbers 1-9. This requires a nested for loop. The outer loop moves from row to row, while the inner loop prints the row. Use tabs to separate the output, such as in the following statement:      System.out.println(“1\t2\t3\t4\t5\t6\t7\t8\t9”); Output should look similar to the following. 1      2     3     4     5     6     7     8     9 ------------------------------------------------------------------ 1       2     3     4     5     6        7     8     9...

  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

    Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Sample program: #include <stdio.h> int main(void) { int userNum = 0; int i =...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • Swapping Values in python Summary In this lab, you complete a Python program that swaps values...

    Swapping Values in python Summary In this lab, you complete a Python program that swaps values stored in three variables and determines maximum and minimum values. The Python file provided for this lab contains the necessary input and output statements. You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate....

  • in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much...

    in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much the same as C's if statement. In-Class Tasks Write LML programs that accomplish each of the following tasks: Use a sentinel-controlled loop to read 10 positive integers and compute and print their sum 1. 2. Use a counter-controlled loop to read seven numbers, some positive and...

  • using mips for assembly language WPte a program that asks the user for 2 numbers. the program should then add the 2 numbers bit by bit, using boolean operators no arithmetic operations ex: add, ad...

    using mips for assembly language WPte a program that asks the user for 2 numbers. the program should then add the 2 numbers bit by bit, using boolean operators no arithmetic operations ex: add, addi, sub, mult, div or arrays are permitted in this project. forming a new variable (in a register) with the solution. That solution is to be output bit by bit using the function that was written in class do not use syscall with a value 10...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT