+ 3
Python Loop Problem
Hello, so i want to create a program that ask the user to enter a number for the start of the loop; end of the loop , and iteration/increment of the loop. is there any source code regarding with this so i can study the loopings? i can't really understand the textbook i have and this problem, i could use some help Thanks! 💙 The output i want to see from it is this: Start: 3 End: 7 Iteration: 2 3 5 The loop has stopped!
5 Réponses
+ 5
Take three inputs and convert them to numeric types -- int or float depending on whether you want to allow numbers with decimals.
Now there are two options:
1. Create a range object with the start, end, and increment values. Use a for loop to print the values.
2. Create a variable set to the start value. Use a while loop with the condition that the value of the variable is less than or equal to the end value. Inside the loop print the value of the variable then add the increment value to the variable
+ 4
Hi, sololearn's Python course might solve your problem.
start with the Python course for beginners and all yours will be clear.
Answering your question, you need three integer value inputs, this is done using the following statement: int(input()).
and create a for loop with the following syntax:
for valeu in range(Start,end,step):
#Print the values here
+ 3
thank you all!
0
the simple code is here:
s=int(input('enter the start value: '))
e=int(input('enter the end value: '))
n=int(input('enter the increment you want: '))
while(s<e):
print(s)
s=s+n
print('loop ended')
- 2
I want to see the code maam