In: Computer Science
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:
#
%
#
%
#
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...