Python Forum
While Loop; Can Else Point Back To Initial Input Command?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While Loop; Can Else Point Back To Initial Input Command?
#3
There is the % operation (modulo operator) in python, do you have the right to use it?
Using the / operator on integers to get how much times you have the second number fitting in the first, and then having the modulo to know how much money you can try with the next one is a more elegant way to do this, I let you figure out how.
>>> 103%25
3
>>> 5 / 2
2
Alternatively, you can do this with while loops, but make sure you have finished to fit in all the quartets before you get to the next one. It can be cleaner to have a separate loop for each, or make use of a for loop to get the right amount of iterations without having to bother with "while true" stuff

>>> a = [25, 10, 5, 1]
>>> for value in a:
...     print value
... 
25
10
5
1
>>> 
Reply


Messages In This Thread
RE: While Loop; Can Else Point Back To Initial Input Command? - by Krookroo - Sep-16-2017, 12:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding string numbers, while loop and exit without input. Jose 11 7,578 Apr-15-2020, 08:34 AM
Last Post: Jose
  Question about running comparisons through loop from input value Sunioj 2 2,429 Oct-15-2019, 03:15 PM
Last Post: jefsummers
  Help with loop & user input rdDrp 11 11,535 Dec-23-2016, 06:10 AM
Last Post: rdDrp
  loop in system command fails roadrage 1 3,661 Dec-01-2016, 11:21 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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