0

How to make the step value when user enter 0 auto set as 1?

https://code.sololearn.com/c7s5fVAMPm21/?ref=app Write a console program that produce display a series of numbers between a starting value and an ending value. User can specify starting and ending values as well as the step value (it used to skip a specified number of steps into the next value). For any multiply of 5, replace the number with "HiFIVE". If the starting value is larger than ending value, the program able to swap between them. For the step value, if user enter 0, the program able to set as 1 automatically.

4th Jun 2020, 6:00 PM
Kyrene
1 ответ
+ 2
From what I understand the implementation for it goes this way It's in python ,see if you can understand what's going ,basically I check if user enters for step value 0 , program will assign value 1 to it and also if starting value is greater than ending value ,both are swapped and then the program prints numbers using while loop starting=int(input("enter the starting value\n")) ending=int(input("enter the ending value\n")) step=int(input("enter number of steps\n")) def print_number(starting,ending,step): if step==0: step=1 if starting>ending: change=starting starting=ending ending=change while starting<ending: starting+=step number=starting if number%5==0: print("High five") elif number>=ending: break else: print(number) print_number(starting,ending,step)
4th Jun 2020, 6:38 PM
Abhay
Abhay - avatar