Python Forum
If statement question help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement question help
#1
Hi guys,

New to this forum and to the programming language. I was hoping someone could help me out with he following task I have been given. Below is my program so far and the question is at the bottom.

guard = bool(input("True or false the guard is present on the gate"))
daytime = int(input ("enter the time of day"))



if (daytime >= 7) and (daytime <= 17):
  print ("You're in!")
  
  
if (daytime < 7) or (daytime > 17) and (guard == True):
  print("You're in!")

else:
  print ("you are not in")
  




I have the beginning of my program, but i am struggling with how to write the second variable on line 10 of my code.
When i set the guard variable to False it still prints "You're in' instead of "You're not in"



At your school, the front gate is locked at night for safety. You often need to study late on campus. There is sometimes a night guard on duty who can let you in. You want to be able to check if you can access the school campus at a particular time.

The current hour of the day is given in the range 0, 1, 2 … 23 and the guard’s presence is indicated by with a True/False boolean.

If the hour is from 7 to 17, you do not need the guard to be there as the gate is open
If the hour is before 7 or after 17, the guard must be there to let you in
Using predefined variables for the hour of the day and whether the guard is present or not, write an if statement to print out whether you can get in.

Example start:
hour = 4
guard = True

Example output:
'You're in!'
Gribouillis write Jan-08-2024, 07:10 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
If statement question help - by Gatso100 - Jan-08-2024, 06:00 PM
RE: If statement question help - by Larz60+ - Jan-08-2024, 07:34 PM
RE: If statement question help - by deanhystad - Jan-08-2024, 08:49 PM
RE: If statement question help - by Larz60+ - Jan-09-2024, 09:31 AM
RE: If statement question help - by Pedroski55 - Jan-09-2024, 11:53 AM

Forum Jump:

User Panel Messages

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