using python
1. Translate the following FOR loops to equivalent
WHILE loops:
a. for count in range(100): print(count)
b. for count in range(1, 101): print(count)
c. for count in range(100, 0, –1): print(count)
# a) count = 0 while count < 100: print(count) count += 1 # b) count = 1 while count < 101: print(count) count += 1 # c) count = 100 while count > 0: print(count) count -= 1
using python 1. Translate the following FOR loops to equivalent WHILE loops: a. for count in...
Please do this in C++ using only for loops, while loops, and do while loops. No arrays. Use for loop, while loop, and do while loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1-256 Note: See Appendix for number systems The program should print the results to the Console without using any string formats Design Details: The Main program should prompt the user for...
Python What do the following loops print? Work out the answer by tracing the code, not by using the computer. a. s = 2 for n in range (1, 6): s = s + n print(s) b. s = 1 for n in range (1, 11): n = n + 2 s = s + n print(s) c. S = 1 for in range (1, 6) s = s + n n = n + 1 print(s, n) Rewrite the...
Which of the following Python loops correctly sums up all of the integers between 1 and 100 (inclusive) and stores the result in a variable called sum? sum = 0 k = 0 while True: sum += k if k > 100: break sum = 0 for k in 1 to 100: sum += k sum = 0 for k in range(100): sum += k sum = 0 k = 1 while k <= 100: sum += k k +=...
What is the output of the following Python code if the user enters 4? count = int(input()) the_sum = 0 for i in range (1, count): the_sum = the_sum + i print("Sum is", the_sum)
Question 4 (1 point) Translate this Python statement to Java: print(n, end=' ') Question 4 options: a. System.out.print(n) b. System.out.print(n + " "); c. System.out.println(n); d. System.println(n + " "); Question 5 (1 point) What is the output of this code fragment? int count = 0; for(int n = 3; n <= 10; n += 2) { count++; } System.out.println(count); Question 5 options: a. 2 b. 3 c. 4 d. 10
How many times are the while and for loops run in the following code? Count the total number of iterations from both the while loop and for loop. p = 32; t = 8; while t <p t=t+ floor(p/pi); for k = 1:2:10 p = p+2; end end Select one: O a. 42 b. 5 c.o o d. 26 o e.30 me to search
Write a section of Java code using while, do-while and for loops Write a section of Java code that will print out random integers between 1 and 100 while N is less than or equal to 5. Sample output > random # 1 is: 73 random # 2 is: 68 random # 3 is: 76 random # 4 is: 64
using C++ 1. Convert the following while loop into a for loop: int count = 0; while (count < 10) x = count + sin(x); y = count + cos(y); count++;
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
[Using Python] Create a program that uses import random and while loops to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered. Your 5 questions should be a simple math problem, like "what is 7-5?"