Using R, Create a while loop which starts x at 1, and prints x: “Are we there yet?” until x reaches 10. (Don’t forget to Increment x by 1 each while loop). To make things interesting, include the line readline(prompt = "Press [enter] to continue") after the print statement stated above. If x is an even number, print x: “Even Number Encountered” And go to the next iteration of the while loop (i.e. No readline – as above)
Hi,
If i have understood your question correctly, please find below the solution in R.
x <- 0
while(x < 10)
{
x <- x + 1
print(paste(x,"Are we there yet?"))
if((x %% 2) == 0)
{
print(paste(x,"Even Number Encountered"))
}
else
{
readline(prompt="Press [Enter] to continue")
}
}
OUTPUT:
[1] "1 Are we there yet?" Press [Enter] to continue [1] "2 Are we there yet?" [1] "2 Even Number Encountered" [1] "3 Are we there yet?" Press [Enter] to continue [1] "4 Are we there yet?" [1] "4 Even Number Encountered" [1] "5 Are we there yet?" Press [Enter] to continue [1] "6 Are we there yet?" [1] "6 Even Number Encountered" [1] "7 Are we there yet?" Press [Enter] to continue [1] "8 Are we there yet?" [1] "8 Even Number Encountered" [1] "9 Are we there yet?" Press [Enter] to continue [1] "10 Are we there yet?" [1] "10 Even Number Encountered"
if i have understood your question correctly, when even number is encountered press enter to continue will not be displayed .are we there yet is printed for all 10 iterations.
Thanks,
Chandana
Using R, Create a while loop which starts x at 1, and prints x: “Are we...
2. Create a while loop which starts x at 1, and prints x: “Are we there yet?” until x reaches 10. (Don’t forget to Increment x by 1 each while loop). To make things interesting, include the line readline(prompt = "Press [enter] to continue") after the print statement stated above. If x is an even number, print x: “Even Number Encountered” And go to the next iteration of the while loop (i.e. No readline – as above)
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...
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an...
Using Python, Can someone please assist in the following:
These are the hints:
Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...
Using Python Version 1. Write a program that uses a "while" loop to print the first 10 positive integers and to compute their sum. Print the sum after it is computed. Do the same with a "for" loop. Version 2. Write a program to approximate the square root of a number. Recall that the square root of a number x is a number r such that r*r = x. Newton discovered that if one initial estimate of r is z...
Need some help I am not understanding this programming class at
all. We are using Microsoft visual studio with python in console
mode to complete these labs.
Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...
Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1. You program will read in a student’s first name. The same will be done for the student’s last name. Your program will use respective methods (described below) to accomplish this. 2. Your program will then read in three quiz scores, respectively. This should be done by using the same method three times. This method is described below. 3. Your program will then calculate the...
I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions only as (DieRoll, Guess, cnt1, cnt2) followed by this statement: srand((unsigned int)time (NULL)); which will give the random number generator a random starting point. Note: srand and rand require the TIME.H (or iomanip) cnt1 and cnt2 will be used in Chapter 5 drop box as counters for loops. Do NOT create additional variables. Points will be taken off for any additional variable creation. 2....
Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...
(Done in Eclipse Java) 1. Given an integer between 1—100 captured from a user, perform the following conditional actions: • If is odd, print Weird • If is even and in the inclusive range of 2 to 5, print Not Weird • If is even and in the inclusive range of 6 to 20, print Weird • If is even and greater than 20, print Not Weird Note: Validate that your algorithm works for all cases. 2. Read an integer...