Question

In: Computer Science

A.) 1. Write a loop that prints the numbers 1-25i.e. B.) 1 2 3 4... 252....

A.) 1. Write a loop that prints the numbers 1-25i.e.

B.) 1 2 3 4... 252. Write a loop that prints all the even numbers between 1 and 50i.e. 2 4 6 8... 483.

C.) Create a list of the following fruits: oranges, apples, grapes and mangos and cherries. Write a loop that prints out every other fruit starting with oranges.i.e. oranges grapes and cherries.

Solutions

Expert Solution

#(a) part...
for i in range(1,26): #range start from 1 to 25..
    print(i,end=" ")   #print number and using end=" " will print number in same line...
print()               

#(b) part....
for i in range(1,51): #from 1 to 50...
    if(i%2==0):   #we will check if number is divisible by 2....
        print(i,end=" ") #will print even number..
print()

#(c) part...
l=['ornages','apples','grapes','mangos','cherries'] #list
for i in range(0,len(l),2):                         #will start from 0 to len(l) but increment is 2...
    print(l[i],end=" ")                             # print list...
print()                                             #will change line..

#########################################################


Related Solutions

Write in assembly 8086. Write a program to input nine numbers in 4*4 array and prints...
Write in assembly 8086. Write a program to input nine numbers in 4*4 array and prints the maximum value of each row and then prints the minimum of each column.
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...
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 In java import java.util.Scanner; public class DivideByTwoLoop { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int userNum; userNum = scnr.nextInt(); *insert code* System.out.println(""); } }
Write a c++ program that prints the count of all prime numbers between A and B...
Write a c++ program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = Any 5 digit unique number B = A + 1000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Write a program that prints the count of all prime numbers between A and B (inclusive),...
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7,...
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5]...
MATLAB PROBLEM convert the for loop to a while loop. vec= [1 2 3 4 5] newVec= [] for i=vec if i>5 new vec=[newvec, i] end end end
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a Java loop statement that prints count. Count begins with 1. It increments as multiples...
Write a Java loop statement that prints count. Count begins with 1. It increments as multiples of 2 and does the loop until count is less than 50.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT