Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 While loop won't restart program :( TheDovah77 Unladen Swallow Posts: 4 Threads: 2 Joined: Apr 2019 Reputation: 0 Likes received: 0 #1 Apr-04-2019, 06:37 PM So I am very new to python, and I am trying to make a simple dice roll simulator. But when I try to loop the program it just doesn't do anything, I've done loops before and am pretty familiar with them (for a noob), but it just doesn't seem to work. This is the code: ```import random z=1 while z==1: y = 1 n = int(input("How many dice do you want to roll?: ")) counter1 = 0 counter2 = 0 counter3 = 0 counter4 = 0 counter5 = 0 counter6 = 0 for x in range (1,n+1): t = random.randint(1,6) while y <= n: if t == 1: counter1 += 1 elif t == 2: counter2 += 1 elif t == 3: counter3 += 1 elif t == 4: counter4 += 1 elif t == 5: counter5 += 1 elif t == 6: counter6 += 1 for x in range (1,n+1): t = random.randint(1,6) y += 1 print("1: ", counter1, " times, 2: ", counter2, " times, 3: ", counter3, " times 4: ", counter4, " times, 5: ", counter5, " times, 6: ", counter6, " times.") z=2 z = int(input("Write 1 to try again: ")) ``` Yoriz Posts: 1,253 Threads: 28 Joined: Sep 2016 Reputation: 121 Likes received: 283 #2 Apr-04-2019, 06:59 PM `z = int(input("Write 1 to try again: ")) `is not indented to be inside of the first while loop. TheDovah77 Unladen Swallow Posts: 4 Threads: 2 Joined: Apr 2019 Reputation: 0 Likes received: 0 #3 Apr-04-2019, 07:22 PM (Apr-04-2019, 06:59 PM)Yoriz Wrote: `z = int(input("Write 1 to try again: ")) `is not indented to be inside of the first while loop. I'm not quite sure I catch what you are saying. It isn't in the first while loop what I can see.... ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 272 Likes received: 1264 #4 Apr-04-2019, 07:26 PM You need to indent the line Yoriz pointed out. The line before that, you set z to 2. That ends the loop, because it only repeats if z is one. Since the last line is not in the loop, you don't get a chance (in the loop) to stay in the loop. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures TheDovah77 Unladen Swallow Posts: 4 Threads: 2 Joined: Apr 2019 Reputation: 0 Likes received: 0 #5 Apr-04-2019, 07:37 PM (Apr-04-2019, 07:26 PM)ichabod801 Wrote: You need to indent the line Yoriz pointed out. The line before that, you set z to 2. That ends the loop, because it only repeats if z is one. Since the last line is not in the loop, you don't get a chance (in the loop) to stay in the loop. Oh I see! Thank you guys! :D « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Hotkey to restart code? DannyB 1 184 May-20-2020, 02:52 AM Last Post: michael1789 Kernel needs to restart ErnestTBass 0 103 May-06-2020, 08:37 PM Last Post: ErnestTBass please help me in loop i am trying to run this program in raspberry pi by sending msg saifullahbhutta 2 168 Jan-27-2020, 02:32 PM Last Post: saifullahbhutta How to rerun the program in a loop with different input? bharaths 3 815 Nov-23-2018, 09:36 AM Last Post: bharaths Nested while loop in pyramid program. raj55 2 2,574 May-04-2018, 10:05 AM Last Post: ThiefOfTime How To Make Script Restart? ghost0fkarma 1 1,124 Dec-07-2017, 01:30 PM Last Post: buran WHILE LOOP in my program kurokszxcky 1 1,455 Oct-02-2017, 03:45 PM Last Post: ichabod801

Forum Jump:

Users browsing this thread: 1 Guest(s)