Need in Python!
Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.
HINT: Stay with i as the main loop counter and let j control the break behavior.
i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1 2 2 4 3 6 4 8 5 10
Need in Python! Consider the following program and expected output. Rewrite it using a for loop...
A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...
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...
Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...
Is the following program correct? If it is correct, what is the output? If it is incorrect, please correct the code and write down the output of the program. def fac(n): i=0 sum=0 while i<=n: sum*=i return sum def main(): print(fac(5)) main() PYTHON PLEASE
The following individual two programs are using while loop in order to print a specific output: The outputs of the first program are: 10 9 8 5 4 The outputs of the second program are: 123456789 Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error: The first program: public Main { public static void main(String args[]){ int i=10 while(i>4){ System.out.print(i); i++; } } } The second program: public class Main {...
When using Python, what exactly is printed when the following program is run? counter = 4 sum = 0 while counter < 7: sum = sum + 2 counter = counter + 1 print ("Value is", sum)
The following individual two programs are using while loop in order to print a specific output: The outputs of the first program are: 10 9 8 5 4 The outputs of the second program are: 123456789 Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error: The first program: public Main { public static void main(String args[]){ int i=10 while(i>4){ System.out.print(i); i++; } } } The second program: public class Main {...
12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers are:') 3 for i in range (2,25): 4 isone (i) 5 def isone (number): isOne = True i = 2 while i < number and is one: if number % i == 0: 10 isOne = False 11 i += 1 Lou if isOne == True: 13 print("\t', i) 14 main() 12 13. What is the output of this program? Your answer: for i...
please rewrite code (IN PYTHON 3.7.4) using a while loop. >>> population = 300000 >>> for year in range (2014, 2019): print("{0:10d} {1:10d}".format(year, int(population))) population = 1.03 * population 2014 2015 2016 2017 2018 300000 309000 318270 327818 337652
Loop Prints hand traced in python. What is the output? Instead of using newlines to separate, use comma to separate each line ie. (a,b,c,...) for i in range(1, 10): if i % 2 == 0: print(i, end=",")