Python Forum
How to Display Multiple Time Tables With While Loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Display Multiple Time Tables With While Loop
#1
I'm trying to write a code which prompts the user to enter a number, then prints its ten-times tables, before moving onto another number (with sentinel value). My code here is not working. The inner while loop is not executing the second time and instead it is simply taking an input, then asking for another input, and again, and again. Any ideas on how to fix this?:

num = int()
counter = int()
counter = 0
counter2 = int()
counter2 = 0


number = num

while counter2 != -1:
    num = int(input("\nEnter a Number: "))   
    counter2 += 1
    while counter <= 9 and num != 1:
        number = num * (counter + 1)
        print(number, end = " ")
        counter += 1
        number = num * (counter + 1)
[python][python]
[/python][/python]
Reply
#2
You need to reset counter to 0 after the inner loop is done executing. Otherwise it retains the final value of 10, and the inner loop never executes.

Also, you don't need to declare variable types in Python, so you don't need lines like num = int(). It is sufficient to use num = 0.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thanks a lot! It works. Appreciate the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,702 May-06-2023, 08:14 AM
Last Post: pramod08728
  Multiple.ui windows showing at the same time when I only want to show at a time eyavuz21 4 993 Dec-20-2022, 05:14 AM
Last Post: deanhystad
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,574 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Multiple Loop Statements in a Variable Dexty 1 1,175 May-23-2022, 08:53 AM
Last Post: bowlofred
  Multiple user defined plots with secondary axes using for loop maltp 1 1,393 Apr-30-2022, 10:19 AM
Last Post: maltp
  Real time Detection and Display Gilush 0 1,762 Feb-05-2022, 08:28 PM
Last Post: Gilush
  How to make for loop display on 1 Line Extra 3 1,376 Jan-12-2022, 09:29 PM
Last Post: Extra
  Slittping table into Multiple tables by rows drunkenneo 1 2,001 Oct-06-2021, 03:17 PM
Last Post: snippsat
  Display table field on multiple lines, 'wordwrap' 3python 0 1,747 Aug-06-2021, 08:17 PM
Last Post: 3python
  Trying to separate a loop across multiple threads stylingpat 0 1,651 May-05-2021, 05:21 PM
Last Post: stylingpat

Forum Jump:

User Panel Messages

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