I am trying to get into coding and this is kinda part of the assignments that i need to do to get into the classes.
In this task, you will implement a check using the if… else structure you learned earlier.You are required to create a program that uses this conditional.
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 = TrueExample output: 'You're in!'
Make use of the if statement structure to implement the program.
One of my ideas was:
Time = int(input("Time of getting in: "))
open = 7
closed = 17
if Time > open and Time < closed:
print("You can not enter")
CodePudding user response:
cap O will solve
Time = int(input("Time of getting in: "))
Open = 7
closed = 17
if Time > Open and Time < closed:
print("You can not enter")
CodePudding user response:
It's not too difficult, you can do a simple function like that :
def go_to_study(hour, start_day = 7, end_day = 17):
if (hour >= start_day and hour <= end_day):
return True
else:
return False
// on one line, uncomment if you want.
// return (hour >= start_day and hour <= end_day)