Question

In: Computer Science

Solve please in python b) Create a program that shows a series of numbers that start...

Solve please in python

b) Create a program that shows a series of numbers that start at a and increase from 5 to 5 until reaching b, where a and b are two numbers captured by the user and assumes that a is always less than b. Note that a and b are not necessarily multiples of 5, and that you must display all numbers that are less than or equal to b.

c) Create a program that displays n characters on the screen that alternate between # and%, where n is an integer entered by the user.
Characters must be displayed one on each line.
Note that the first character to display is always #

For example:
If n = 5, you should show:
#
%
#
%
#

Solutions

Expert Solution

In this Python program,

Code a: Here, we are prompting the user to enter the values of a and b then we are iterating through the for loop starting from a with an increment of 5 till it reaches b with a loop variable i. Then we are printing the value i.
Code b: Here, we are prompting the user to enter the value of n then we are using a for loop starting from 1 to n(inclusive) then for odd indexes we are printing # and fir even indexes we are printing %.
(NOTE: Check the screenshot for Indentation, Usually this compiler will remove all the indentation that I mentioned)

(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)

Code b:

#Prompting and then reading the values of both a and b
a=int(input("Enter the value of a: "))
b=int(input("Enter the value of b: "))


print("The Range from",a,"to",b,"is")
#Iterating from a with an increment of 5 till it reaches b
for i in range(a,b+1,5):
print(i)

Code c:

#Prompting the user to enter the value of n
n=int(input("Enter the value of n: "))

#Iterating through all the values till we reach n
for i in range(1,n+1):
#Check if it is an odd index(1,3,5,...) print #
if(i%2!=0):
print("#")
#Check if it is an even index(2,4,6,...) print %
else:
print("%")

Please check the compiled program and its output for your reference:
Code-a:


Output:

Code b:

Output:

Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...


Related Solutions

Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,
Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
write a python program, please. Create a program that uses the Gettysburg Address as input and...
write a python program, please. Create a program that uses the Gettysburg Address as input and outputs a list of tuples for every two words. For example: [('Four', 'score'),('and', 'seven'), ...].
Please use Python 3 3). Write a function that writes a series of random numbers to...
Please use Python 3 3). Write a function that writes a series of random numbers to a text file named ‘random_number.txt’. Each random number should be in the range of 1 through 500. The function should let the user specify how many random numbers the file will hold. Then write another function that reads the random numbers from the ‘random_number.txt’ file, displays the numbers, and then displays the total of the numbers and the number of random numbers read from...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Please write in Python code please Write a program that creates a dictionary containing course numbers...
Please write in Python code please Write a program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (key) Room Number (value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary containing course numbers and the names of the instructors that teach each course. The dictionary should have the following key-value pairs: Course...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT