Question

In: Computer Science

2) create a python program that uses a for loop and range to print out the...

2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2

3) Create a python program that yses a for loop to print out ["bob","al","bert"]

Solutions

Expert Solution

2.

Code screenshot:

Output:

Code to copy:

# range() in python has 3 parameters
# The first one is the starting value. Here we need to print from 10 so start = 10
# The second is stop value. Here we need to print till 2 so we give a value that comes
# just after that. So stop = 0
# The third is step. That is the increment or decrement in each iteration

# Now using a for loop we can iterate an integer through this range
for i in range(10, 0, -2):
# and print value that integer in each iterations
print(i)

3.

Code screenshot:

Output:

Code to copy:

# We need to give the list to the for loop and

# use an iterator to go through each element in list

for i in ["bob", "al", "bert"]:

    # and print each of the elements that comes into iterator

    print(i)



Related Solutions

Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
pyramid.py program for i in range(1,6): for j in range(i): print("*",end=' ') print("\n",end='') Exercise: Create the...
pyramid.py program for i in range(1,6): for j in range(i): print("*",end=' ') print("\n",end='') Exercise: Create the pyramid similar to the above pyramid.py program using a while loop. Name your program whilepyramid.py and submit it on blackboard.
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
Create a python program that contains a while loop together with a Sentinel (0) to process...
Create a python program that contains a while loop together with a Sentinel (0) to process indefinite item costs that are purchased online from a vendor. Be sure that you assign a variable SENTINEL to 0 to use in the Boolean condition of your while loop. A sales tax rate of 6.25% is applied to the subtotal for the items purchased. Be sure you assign a variable, TAXRATE to 0.0625. The program is to process a number of items, numItems,...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: 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...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a...
>>python Question: Create program which acquires an integer in the range 1-17, and then outputs a times table from that acquired figure. Function should print times table and another function which acquires and returns the ranged integer. Therefore they are distinct functions. Specific details to include: You can also in the central area of the code script allocate a value which is returned aside a function to a variable.(For example table=yourchoiceinteger(1,17).) Therefore that table which is the variable will be...
Python Write a for loop with a range function and format output as currency Use an...
Python Write a for loop with a range function and format output as currency Use an input statement to ask the user for # of iterations using the prompt: #? [space after the ?] & assign to a variable Convert the variable to an integer Use a for loop and a range function to display all whole numbers from 1 to the user entered number Display the value of the item variable on screen in each iteration in the following...
Create a for loop that will print numbers 57, 21, 99, 10, 80
Create a for loop that will print numbers 57, 21, 99, 10, 80
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT