Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement [Guard List]
#1
hello everyone, im a  soldier and in my unit there is a lot of guard duty which means that everyday each soldier have a 3 hours guard duty which he takes care of an a specific area.
there is a specific guy which makes the list of the guards keeping time and what im trying to make is a program which make that list automatic without a man manualy making it.
there is 2 areas that sometimes your guard there sometimes there so here is what i made for now :

from random import *
guards = [] #here there is the names of all the available guards!
newguards = []
guardscount = input('How many guards guard?:')
for i in range(0,int(guardscount)):
   i = input('What is the guard name:?')
   guards.append(i)

guardians = {}
times = ['23:00-2:00','00:00-03:00','02:00-05:00','03:00-06:00','05:00-08:00','06:00-09:00','08:00:11:00','09:00-12:00',
         '11:00-14:00','12:00-15:00','14:00-17:00','15:00-18:00','17:00-20:00','18:00-21:00','20:00-23:00','21:00-00:00']
day = 21
month = 3
index = 15
while day < 23:
   for x in guards:
       guardians[x] = times[randint(0, index)]
       times.remove(guardians[x])
       index -= 1
       if index == 0 :
           print('Today', day, '/', month, 'This is the Guardians List:', guardians)
           times = ['23:00-2:00','00:00-03:00','02:00-05:00','03:00-06:00','05:00-08:00','06:00-09:00','08:00:11:00','09:00-12:00',
                        '11:00-14:00','12:00-15:00','14:00-17:00','15:00-18:00','17:00-20:00','18:00-21:00','20:00-23:00','21:00-00:00']
           index = 15
           day += 1

   if len(guards) == 0:
       guards = newguards
       newguards = []
       continue
the problem i have here is that somehow the if index =0 statment apply even when index is not 0 i dont know why..

sorry about my english...its not my home language so..

Moderator:
sparkz_alot: removed formating from code
Reply


Messages In This Thread
If statement - by yuvalsaias - Mar-22-2017, 01:54 PM
RE: If statement - by buran - Mar-22-2017, 02:09 PM
RE: If statement - by sparkz_alot - Mar-22-2017, 02:18 PM
RE: If statement [Guard List] - by nilamo - Apr-17-2017, 04:19 PM
Need Help with a program - by yuvalsaias - Apr-17-2017, 11:08 AM
RE: Need Help with a program - by sparkz_alot - Apr-17-2017, 12:55 PM
RE: Need Help with a program - by Mekire - Apr-17-2017, 01:46 PM
RE: Need Help with a program - by yuvalsaias - Apr-17-2017, 02:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,704 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Change a list to integer so I can use IF statement buckssg 3 2,275 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  How to invoke a function with return statement in list comprehension? maiya 4 2,911 Jul-17-2021, 04:30 PM
Last Post: maiya
  An IF statement with a List variable dedesssse 3 8,377 Jul-08-2021, 05:58 PM
Last Post: perfringo
  using element on a list as condition statement glennford49 11 5,050 May-21-2020, 12:53 PM
Last Post: hussainmujtaba
  Help: list comprehension for loop with double if statement mart79 3 2,466 May-04-2020, 06:34 AM
Last Post: buran
  Taking brackets out of list in print statement pythonprogrammer 3 2,431 Apr-13-2020, 12:25 PM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 2,159 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Checking for an item in a list (if then statement) Sailnir 1 2,082 Jul-18-2019, 05:36 PM
Last Post: ndc85430
  skeleton class needs working instantiation guard hereathome 3 3,073 Dec-10-2017, 03:35 PM
Last Post: hshivaraj

Forum Jump:

User Panel Messages

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