Question

**Using a for loop and range command, print the sequence
of numbers from 1 to 20 (skipping two numbers for each element);
that is, your code should print out the numbers 1,4, 7, 10, … (max
should not exceed 20). Use x as the variable name**

Answer #1

In python programming language, we can print sequence of numbers using for loop and range command.

Given data,

**Input:** Numbers from 1 to 20

**Output:** sequence of numbers 1,4,7,10....

**Condition:** output should not exceed 20 and
skipping two numbers for each element.

**Program:**

# consider variable name as x

for x in range(1,20+1,3):

print(x)

**Explanation:**

we have to give 20+1 because range considers the given number with -1. It means if we have given as 20 it considers the value upto 19 only. So inorder to print upto 20 give as 20+1.

The syntax for range is :

range(start value, stop value, increment steps)

In our code, range starts from 1 and ends with 20 with increment of 3 steps.

Uses a while loop to print the numbers from 3 - 19.
Uses a do-while loop to print the numbers from 42 - 56.
Uses a for loop to print the numbers from 87 - 95.
Asks the user for 2 numbers. Uses a loop to print all numbers
between the given numbers, inclusive.
Note: Consider that your user's second number can be lower!
(see example below)
Note: Also consider that your user might give you two of the
same...

Using Python and the command of for loop and range, while loop,
if_elif_else ,
1. In this problem you must design an algorithm to identify
whether a number is
multiple of 3, 5 and 7 . That is, the algorithm receives
a number and must tell the user if the number is:
(make a program)
• only multiple of 3
• only multiple of 5
• only multiple of 7
• only multiple of 3 and 5
• only multiple of...

In Java programming language
11.Create the code for a for loop to print the numbers
1 through 5 inclusive vertically so the output is
1
2
3
4
5
11b What is the output of the
following OUTPUT
int i=3;
while(int i >0)
{
System.out.println(i);
i--;
}
11c What is the output of the
following OUTPUT
for(int i=3;i<10;i++)
System.out.println(3*i);
11d Create the line of code to print the numbers 10 through 1
decreasing by 1 each time
11e Create the line of code...

1) Write a java programming using a while
loop where you will add numbers and when you
press number 0 it will add all your
numbers and display the results.
Use Scanner object.
Steps:
1) Declare variables integer called sum which is equal to
zero
2) Declare Scanner object
3) Declare while condition where is true
4) Inside of that condition prompt the user to enter
the numbers
5) Declare variable integer called number and input
the number statement
6)...

Using a for Loop visual c++
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
Write a for loop that uses the loop control
variable to take on the values 0 through 10.
In the body of the loop, multiply the value of the loop control
variable by 2 and...

USING MATLAB
(A) Use the rand command to generate “X” of size [10000 1] and
the command histogram to plot the probability distribution of “X”
along with axis labels and a title that includes the mean and
variance for “X”. (B) Use a while loop and the rand command to
generate “X1”, also of size [10000 1] but with each element of “X1”
being the mean of 2 “samples” generated using rand, i.e. a “sample
size” of 2 separate numbers...

Write a code segment to print your name ten times on the screen
using a while loop. Use one variable
called count to act as a counter for the
loop. Discuss how would you print your name 1000 times on the
screen.
NOTE:
You can either type your code into the text box or upload a
document to the discussion board by clicking the "attach" clip at
the bottom left of the discussion box.

Take 10 numbers from the user. Calculate their mean and median
with your code, not using builtin Matlab functions. Print these
values on the screen with a special format using the command:
fprintf.

Write the function most_factors(numbers) that returns the
integer from the list numbers that has the most factors (divisors
without remainder). For example:
>>> most_factors([5,10,16,20,25])
20 # because 20 has the most factors of any of these numbers
# 6 factors, i.e., [1, 2, 4, 5, 10, 20]
>>> most_factors([1, 2, 3, 4, 5])
4 # because 4 has the most factors of any of these numbers
# 3 factors, i.e., [1, 2, 4]
Hints:
For each element in numbers, call...

***Python
Hailstones, also known as the Collatz
sequence, are a mathematical curiosity. For any number in the
sequence, the next number in the sequence is determined by two
simple rules:
If the current number n is odd, the next number in the
sequence is equal to 3 * n + 1
If the current number n is even instead, the next
number in the sequence is equal to one half of n (i.e.,
n divided by 2)
We repeat this...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 4 minutes ago

asked 37 minutes ago

asked 52 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago