Python Forum
How give an for loop an maximum number, help pleace ?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How give an for loop an maximum number, help pleace ?
#4
(Aug-08-2017, 07:00 PM)JamieVanCadsand Wrote:
(Aug-08-2017, 01:55 PM)ichabod801 Wrote: I don't know what you are trying to do. I don't understand "'for loop' an max number." Please explain exactly how the output you are getting is not the output you are expecting.

That said, I see a lot of issues with your code. Mostly you are doing a lot of stuff you don't need to do. The output of input is a string, so you don't need to make it a string again with str() on line 5. The math.floor function returns the largest integer <= the input. There is no reason to use it on an integer on line 12. arrayRange += 0 adds zero to arrayRange. That is, it does nothing. On line 28 you confirm press is 'A', so there is no reason to set it to 'A' on line 29.

The main problem I see is that you use the variable name arrayRange in four different places. Once to get user input, and three times as three different loop variable. Each loop should have it's own variable, distinct from other variables. Your loops should be something like this:

for loop_variable in range(start, finish):
The above loop will take the values from start to finish - 1 and put them in the variable loop_variable. Again, each loop should have a different variable name in the place of loop_variable.

OK... sorry for my too complex code... Now I get
an other way to give it an max...

An code like this:
question = str(input("Your Name: "))

numbs = range(int(Input("Range Number")))

for numbs in numbs:
    print("Your name is ", question)

(Aug-08-2017, 07:00 PM)JamieVanCadsand Wrote: OK... sorry for my too complex code... Now I get
an other way to give it an max...

An code like this:
question = str(input("Your Name: "))

numbs = range(int(Input("Range Number")))

for numbs in numbs:
    print("Your name is ", question)

The problem with my code is fixed....

Now I do for numbs in numbs and tha print my string...
But thanks....

Jamie.


Oops... Sorry for my empty code...
Reply


Messages In This Thread
RE: [Beginner] How give an for loop an maximum number, help pleace ? - by JamieVanCadsand - Aug-09-2017, 08:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Give visit number ( or counter) within the same time frame balthordu 1 996 Jun-27-2022, 09:51 AM
Last Post: Larz60+
  Give a number for Variable quest 2 1,558 Jan-31-2022, 08:35 AM
Last Post: ibreeden
  How to verify the give number is valid Mekala 3 2,478 May-16-2020, 02:40 PM
Last Post: anbu23
  number repeating twice in loop JonnyEnglish 3 3,364 Nov-24-2019, 09:23 AM
Last Post: ThomasL
  Is 2 a prime number? for loop & range fuction in python docs says yes, mine says no. allusernametaken 4 2,986 Nov-17-2019, 02:56 AM
Last Post: allusernametaken
  Setting maximum value of Range() in For loop pmt 4 2,643 Aug-04-2019, 02:38 PM
Last Post: pmt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020