Question

Python programming: Write a while loop that prints a. All squares less than n. For example,...

Python programming: Write a while loop that prints a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
n = 100

#Code a
i = 0
while(i*i<n):
    print(i*i)
    i+=1
print()


#Code b
i = 10
while(i<n):
    print(i)
    i+=10
print()


#Code c
i = 1
while(i<n):
    print(i)
    i*=2
print()

Add a comment
Know the answer?
Add Answer to:
Python programming: Write a while loop that prints a. All squares less than n. For example,...
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
  • Write a while loop that prints all positive numbers that are divisible by 10 and less...

    Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("n: ");        int n = in.nextInt();        ...        while (...)        {           ...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • Write a C++ program that will calculate average of squares up to n. For example, if...

    Write a C++ program that will calculate average of squares up to n. For example, if user enters 3 the function should display 1 + 4 + 9/ 3 = 4.6667. Requirements Created function to receive 1 parameter and no return parameter. Called the new function from main function inside a while loop. Calculated the sum of squares and average correctly in the new function using loop with no library functions. Sample Output ~~Enter a number ONLY between 1 and...

  • in Java programming Using IF statement, write a program that prints multiplication table for 1-10. Sample...

    in Java programming Using IF statement, write a program that prints multiplication table for 1-10. Sample Program Output. 1     2     3     4     5     6     7     8     9     10       1     1     2     3     4     5     6     7     8     9     10       2     2     4     6     8     10    12    14    16    18    20       3     3     6     9     12    15    18    21    24    27    30       4     4     8     12    16    20    24    28    32    36    40       5     5     10   ...

  • Write while loop to display the numbers from 10 through 1 and the squares. The output...

    Write while loop to display the numbers from 10 through 1 and the squares. The output should display as following: n squared 10 100 9 81 8 64

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • 1. Write a for loop that prints the sum of all positive even integers less than...

    1. Write a for loop that prints the sum of all positive even integers less than 200. Assume that variables i and sum are already declared. 2. Write a while loop that prints the sum of all positive odd integers less than 100. Assume that variables i and sum are already declared. 3. Write a do-while loop that prints the sum of all positive multiples of 3 less than or equal to 150. Assume that variables i and sum are...

  • Ex1 In Python Write a while loop that prints out a list containing the first 5...

    Ex1 In Python Write a while loop that prints out a list containing the first 5 numbers that are multiples of 9 from 1 to 100. (Hint: use break statement) The output should be [9, 18, 27, 36, 45]

  • Python programming Question 1: Write a script with a for loop that prints each character in...

    Python programming Question 1: Write a script with a for loop that prints each character in your first name written as first initial capital and other small, followed by its ASCII value on the screen.  Use appropriate functions to get character value to ASCII code. (Hint: Functions discussed in lectures)  For example, the output of each iteration should be as -- for ‘A’, it should print A followed by its ASCII value. Question 2: Write a script that...

  • Given positive integer num_insects, write a while loop that prints that number doubled up to, but...

    Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow each number with a space. Ex: If num_insects == 8, print: 8 16 32 64 num_insects = 8 # Must be >= 1

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