New Question!!!
Without using any Conditional contruct and Strings , print the following series:-
0,5,0,5...Nth term
#ShortestProgramPossible
Share
New Question!!!
Without using any Conditional contruct and Strings , print the following series:-
0,5,0,5...Nth term
#ShortestProgramPossible
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Required Answer:-
Question:
Without using conditional construct and strings, print the following series upto nth term.
0 5 0 5...
Solution:
Here comes the program. This might be the shortest program possible.
n,a,b=int(input("Enter limit - ")),0,5
for i in range(n):
print(a&5,end=" ")
a,b=b,a
If you don't know about bitwise 'and', then you can use this approach.
n=int(input("Enter the range - "))
a,b=0,5
for i in range(n):
print(a,end=" ")
a+=b
b*=-1
Algorithm:
Refer to the attachment for output ☑
[tex]\textsf{\large \textbf{Program}}[/tex]
[tex]\texttt{N = int(i \hspace{-1em} nput(`Enter N - '))}\\\texttt{print(*([0, 5] * N)[:N])}[/tex]
[tex]\textsf{\large \textbf{Algorithm}}[/tex]
[tex]\textsf{\textemdash \: Getting the number of terms (N)}\\\textsf{\textemdash \: Coping the pattern (0, 5) \textit{N} times}\\\textsf{\textemdash \: Slicing the list up to the Nth term}\\\textsf{\textemdash \: Unpacking the list hence, displaying the series}[/tex]