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

Create a python program that will ask the user for his job title and print out...
Create a python program that will ask the user for his job title and print out the first letter, the last letter and the total number of letters in his job
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.
Write a Python program that print out the list of couples of prime numbers that are...
Write a Python program that print out the list of couples of prime numbers that are less than 50, but their sum is bigger than 40. For instance(29,13)or(37,17),etc. Your program should print all couples
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the...
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the number is equal to 99, display "Ninety-nine", otherwise display "no-match". If the number is equal to 75, display "Seventy-five", otherwise display "no-match".
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
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"
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...
Using the software Emulator EMU8086, write an assembly program that uses a loop to print "HELLO...
Using the software Emulator EMU8086, write an assembly program that uses a loop to print "HELLO WORLD" 3 times and "LIFE" 2 times. Example: HELLO WORLD HELLO WORLD HELLO WORLD LIFE LIFE   
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"...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT